amazon-web-services - Terraform Destroy Command 显示不正确的计划
问题描述
我是 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 计划文档:
默认情况下,plan 不需要标志,并在当前目录中查找要刷新的配置和状态文件。
推荐阅读
- c# - 在 C# 中检索网络共享权限的问题
- java - spring 如何使用 localhost 而不是 localhost IP?
- r - gsub 匹配后的第一个单词
- java - 如何将麦克风音频流式传输到同一设备抛出扬声器
- wso2 - 构建WSO2 EI 6.5.0的源代码
- facebook - Facebook webhook,如何从中间 id 获取对话 id
- javascript - 在片段中加载 jQuery 并将元素添加到空白页面
- c# - 无法将要分配的类实例声明为库函数的输出参数
- javascript - 2个数组中的反应对象
- mysql - 选择分配给用户的具有有限权限的所有用户的进程列表