Amazon web services 地形破坏命令显示计划不正确
我现在还不熟悉地形和学习。我已经使用terraform代码创建了一个aws实例,它在我的测试环境中工作。我用terraform destroy消灭了同一个实例,它成功了。现在,当我尝试创建新实例时,terraform plan显示了要添加的2个资源,而不是1个。下面是我的计划输出Amazon web services 地形破坏命令显示计划不正确,amazon-web-services,terraform,terraform-provider-aws,Amazon Web Services,Terraform,Terraform Provider Aws,我现在还不熟悉地形和学习。我已经使用terraform代码创建了一个aws实例,它在我的测试环境中工作。我用terraform destroy消灭了同一个实例,它成功了。现在,当我尝试创建新实例时,terraform plan显示了要添加的2个资源,而不是1个。下面是我的计划输出 C:\terraform>terraform plan Refreshing Terraform state in-memory prior to plan... The refreshed state wil
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.
您的地形图显示它将添加两个资源:一个aws_实例和一个aws_密钥对。aws_密钥对允许您 这是因为当您运行terraform plan时,terraform会查看当前目录中的所有.tf文件,并尝试创建它找到的所有资源。您可以通过从当前目录中删除aws_key_pair.tf来修复此问题,这使得terraform plan只能找到要创建的aws_实例 有关更多详细信息,请参阅文档: 默认情况下,计划不需要标志,并在当前目录中查找要刷新的配置和状态文件
请编辑您的问题并分享您的地形图输出。谢谢嗨,我现在刚接触地形和学习。我已经使用terraform代码创建了一个aws实例,它在我的测试环境中工作。我用terraform destroy清除了同一个实例,并且成功了。现在,当我尝试创建新实例时,terraform计划显示要添加2个资源,而不是1个。下面是我的计划输出。计划:2添加,0更改,0销毁。我通过在aws_instance.tf文件的末尾添加key_name=xy对来修复它,并从terraform目录中删除了aws_key_pair.tf文件,现在它工作得很好。请帮助我了解aws密钥对角色,。