无法执行terraform apply
我是terraform的初学者。
结论
只有在与 main.tf 相同的目录中才能执行 terraform apply。
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”。辛苦你了。