LoginSignup
1
1

More than 3 years have passed since last update.

terraform apply が実行できない

Last updated at Posted at 2021-03-21

terraform 初心者です。

結論

terraform apply は main.tf と同じディレクトリではないと、実行できない。

Test1
└── Test2
     ├── main.tf
     └── terraform.tfstate
$ cd Test1
$ ls
terraform_test

# main.tf より上の階層(Test1)で terraform apply を打つと…
$ terraform apply
Error: No configuration files

Apply requires configuration to be present. Applying without a configuration
would mark everything for destruction, which is normally not what is desired.
If you would like to destroy everything, run 'terraform destroy' instead.

うまくいきません。
そこで、階層を変えます。

~ master*
$ cd Test2
$ ls
main.tf           terraform.tfstate

# main.tf と同じ階層(Test2)で terraform apply を打つと…
$ terraform apply   
aws_instance.example: Refreshing state... [id=i-0dde93a30067c72a1]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_instance.example will be updated in-place
  ~ resource "aws_instance" "example" {
        id                           = "i-0dde93a30067c72a1"
      ~ tags                         = {
          + "Name" = “Hello”
        }
        # (26 unchanged attributes hidden)




        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 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: Modifying... [id=i-0dde93a30067c72a1]
aws_instance.example: Modifications complete after 1s [id=i-0dde93a30067c72a1]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

無事に実行されました。
ちなみに、上述のコードは、EC2インスタンスのタグをHelloにしようとしています。
お疲れ様でした。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1