【问题标题】:Terraform Destroy Command shows improper planTerraform Destroy Command 显示不正确的计划
【发布时间】:2019-08-09 22:02:28
【问题描述】:

刚接触 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 计划输出。谢谢!
  • 嗨,我是 Terraform 的新手,现在正在学习。我使用有效的 terraform 代码创建了一个 aws 实例(我有测试环境)。我使用“terraform destroy”清除了同一个实例,它成功了。现在,当我尝试创建新实例时,“terraform plan”显示要添加 2 个资源而不是 1 个。下面是我的计划输出。
  • 计划:2增加,0改变,0破坏。
  • 我通过在 aws_instance.tf 文件的末尾添加 key_name="xy-pair" 来修复它,并从 terraform 目录中删除了 aws_key_pair.tf 文件,现在它运行良好。帮助我了解这里的 aws_key_pair 角色。

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

您的 Terraform 计划显示它将添加 2 个资源:aws_instanceaws_key_pairaws_key_pair 允许您 control login access to your EC2 instance.

这是因为当您运行 terraform plan 时,Terraform 会查看当前目录中的 所有 .tf 文件并尝试创建它找到的所有资源。您可以通过从当前目录中删除 aws_key_pair.tf 来解决此问题,这使得 terraform plan 只能找到要创建的 aws_instance

有关详细信息,请参阅terraform plan 文档:

默认情况下,plan 不需要任何标志,并在当前目录中查找要刷新的配置和状态文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 2021-12-27
    • 2021-02-23
    • 1970-01-01
    • 2020-05-06
    相关资源
    最近更新 更多