[英]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.