[英]Terraform (0.12.29) import not working as expected; import succeeded but plan shows destroy & recreate
[英]Terraform Destroy Command shows improper plan
我是 Terraform 的新手,现在正在学习。 我使用有效的 terraform 代码创建了一个 aws 实例(我有测试环境)。 我使用“ terraform destroy
”消灭了同一个实例,它成功了。 现在,当我尝试创建新实例时,“ terraform plan
”显示要添加的 2 个资源而不是 1 个。下面是我的计划输出。
C:\terraform>terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
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
id: <computed>
ami: "ami-051f75c651d856381"
arn: <computed>
associate_public_ip_address: <computed>
availability_zone: <computed>
cpu_core_count: <computed>
cpu_threads_per_core: <computed>
ebs_block_device.#: <computed>
ephemeral_block_device.#: <computed>
get_password_data: "false"
host_id: <computed>
instance_state: <computed>
instance_type: "t2.micro"
ipv6_address_count: <computed>
ipv6_addresses.#: <computed>
key_name: <computed>
network_interface.#: <computed>
network_interface_id: <computed>
password_data: <computed>
placement_group: <computed>
primary_network_interface_id: <computed>
private_dns: <computed>
private_ip: <computed>
public_dns: <computed>
public_ip: <computed>
root_block_device.#: <computed>
security_groups.#: <computed>
source_dest_check: "true"
subnet_id: <computed>
tenancy: <computed>
volume_tags.%: <computed>
vpc_security_group_ids.#: <computed>
+ aws_key_pair.deployer
id: <computed>
fingerprint: <computed>
key_name: "key-pair"
public_key: "XXX"
Plan: 2 to add, 0 to change, 0 to destroy.
您的 Terraform 计划显示它将添加 2 个资源:一个aws_instance
和一个aws_key_pair
。 aws_key_pair
允许您控制对 EC2 实例的登录访问。
这是因为当您运行terraform plan
,Terraform 会查看当前目录中的所有.tf
文件并尝试创建它找到的所有资源。 您可以通过从当前目录中删除aws_key_pair.tf
来解决此问题,这使得terraform plan
只能找到要创建的aws_instance
。
有关更多详细信息,请参阅terraform 计划文档:
默认情况下,计划不需要标志并在当前目录中查找要刷新的配置和状态文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.