简体   繁体   中英

Terraform Destroy Command shows improper plan

Am New to Terraform and learning now. I have created an aws instance using terraform code which worked (I have test environment). I wiped out same instance using " terraform destroy " and it went successful. Now, when i try to create new instance, " terraform plan " shows 2 resources to be added instead of 1. below is my plan output.

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 . An aws_key_pair allows you to control login access to your EC2 instance.

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. 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.

See the terraform plan documentation for more details:

By default, plan requires no flags and looks in the current directory for the configuration and state file to refresh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM