wardviaene / terraform-course

Course files for my Udemy course about Terraform
https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT
1.59k stars 4.02k forks source link

ERROR executing Demo-1 #26

Closed hitesh-goel closed 4 years ago

hitesh-goel commented 4 years ago

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.example will be created
  + resource "aws_instance" "example" {
      + ami                          = "ami-06b94666"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.micro"
      + ipv6_address_count           = (known after apply)
      + ipv6_addresses               = (known after apply)
      + key_name                     = (known after apply)
      + network_interface_id         = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      + security_groups              = (known after apply)
      + source_dest_check            = true
      + subnet_id                    = (known after apply)
      + tenancy                      = (known after apply)
      + volume_tags                  = (known after apply)
      + vpc_security_group_ids       = (known after apply)

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }

      + root_block_device {
          + delete_on_termination = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_instance.example: Creating...

Error: Error launching source instance: UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message: aksjfhalsfncalkshjasjdfalsdhfaljsdflsisomerandomshit

status code: 403, request id: da12aa68-9933-4705-9915-5a0db00ae25a

  on instance.tf line 1, in resource "aws_instance" "example":
   1: resource "aws_instance" "example" {

the user i am using has Administrator access. Still, i am getting this error. What's the issue?

wardviaene commented 4 years ago

Are you allowed to create an instance in the region you're specifying? You might want to try another region. You might want to first create an EC2 instance manually with the same user to see whether that works.

-Edward

hitesh-goel commented 4 years ago

Yes, I am able to create an instance in the region us-west-2 using console but not using terraform in first-step. My account is not Admin one but I have the AdministratorAccess.

wardviaene commented 4 years ago

Check your ~/.aws/ directory. Maybe you have other credentials still configured. Also make sure to have changed provider.tf to deploy in us-west-2 instead of eu-west-1

hitesh-goel commented 4 years ago

Found the error: Root cause was my AWS account was enabled with MFA and to instantiate the EC2 instance it requires MFA. Due to not valid configuration of MFA. I was not able to instantiate the EC2.

Thanks for all the help. Closing this issue.