是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.
答案 0 :(得分:0)
您的Terraform计划表明它将添加2个资源:aws_instance
和aws_key_pair
。 aws_key_pair
允许您control login access to your EC2 instance.
这是因为,当您运行terraform plan
时,Terraform会查看当前目录中.tf
文件的全部并尝试创建它找到的所有资源。您可以通过从当前目录中删除aws_key_pair.tf
来解决此问题,这使得terraform plan
只能找到要创建的aws_instance
。
有关更多详细信息,请参见terraform plan文档:
默认情况下,计划不需要标志,并在当前目录中查找要刷新的配置和状态文件。