简体   繁体   English

Terraform Destroy Command 显示不正确的计划

[英]Terraform Destroy Command shows improper plan

Am New to Terraform and learning now.我是 Terraform 的新手,现在正在学习。 I have created an aws instance using terraform code which worked (I have test environment).我使用有效的 terraform 代码创建了一个 aws 实例(我有测试环境)。 I wiped out same instance using " terraform destroy " and it went successful.我使用“ terraform destroy ”消灭了同一个实例,它成功了。 Now, when i try to create new instance, " terraform plan " shows 2 resources to be added instead of 1. below is my plan output.现在,当我尝试创建新实例时,“ 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.

Your Terraform plan was showing that it would add 2 resources: an aws_instance and an aws_key_pair .您的 Terraform 计划显示它将添加 2 个资源:一个aws_instance和一个aws_key_pair An aws_key_pair allows you to control login access to your EC2 instance. aws_key_pair允许您控制对 EC2 实例的登录访问。

This is because when you run terraform plan , Terraform looks at all of the .tf files in the current directory and tries to create all of the resources it finds.这是因为当您运行terraform plan ,Terraform 会查看当前目录中的所有.tf文件并尝试创建它找到的所有资源。 You were able to fix this by removing aws_key_pair.tf from the current directory, which made it so terraform plan could only find the aws_instance to create.您可以通过从当前目录中删除aws_key_pair.tf来解决此问题,这使得terraform plan只能找到要创建的aws_instance

See the terraform plan documentation for more details:有关更多详细信息,请参阅terraform 计划文档:

By default, plan requires no flags and looks in the current directory for the configuration and state file to refresh.默认情况下,计划不需要标志并在当前目录中查找要刷新的配置和状态文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform (0.12.29) 导入未按预期工作; 导入成功,但计划显示销毁和重新创建 - Terraform (0.12.29) import not working as expected; import succeeded but plan shows destroy & recreate 地形计划命令失败 - Terraform plan command failing Github 操作恢复/销毁 terraform Terraform 计划创建的 AWS 基础设施 - Github Actions revert/destroy terraform AWS infrastructure created by Terraform Plan Terraform 计划显示已应用的 CanonicalUser 更改 - Terraform plan shows changes for CanonicalUser that are already applied 如果设置了 prevent_destroy 生命周期,则 Terraform 计划显示错误 - Terraform plan showing error if prevent_destroy lifecycle is set 每天为开发环境运行 `terraform destroy` 命令 - Running `terraform destroy` command daily for dev environments Terraform 导入和计划显示用户数据发生变化,而没有变化 - Terraform Import and Plan shows change in user data whereas there is no change 导入 aws 资源后 Terraform 计划显示差异 - Terraform plan shows differences after importing the aws resources S3 存储桶 - Terraform:计划在默认值上显示不存在的更改 - S3 bucket - Terraform: Plan shows inexistent changes, on default values AWS CloudFormation是否具有等效的Terraform destroy命令 - Does AWS CloudFormation have an equivalent Terraform destroy command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM