hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.75k stars 9.1k forks source link

[Bug]: The resource aws_instance does not import network interface block. #30055

Open rutujachaudhari124 opened 1 year ago

rutujachaudhari124 commented 1 year ago

Terraform Core Version

0.12.31

AWS Provider Version

2.70.0

Affected Resource(s)

aws_instance

Expected Behavior

When resource aws_instance is imported, the network interface block must be added to the state file with other parameters which contains the information of the network interface attached, similar to the ebs block devices.

Terraform import should add details in such format in the state file after import:

"network_interface": [ { "delete_on_termination": false, "device_index": 0, "network_interface_id": "*****" } ],

Actual Behavior

When this resource aws_instance is imported, in the tf state file we can see that the network_interface details are not added. It is mentioned as network_interface = [].

The id of primary network_interface is visible as an attribute in the state file, but the network interface block seems empty.

Relevant Error/Panic Output Snippet

When we add the network interface configuration, and perform terraform apply, the force replacement is observed and we can see 1 to add and 1 to destroy. It tries to destroy and recreate.

Error:
 + network_interface { # forces replacement
          + delete_on_termination = false
          + device_index          = 0
          + network_interface_id  = "****************"
        }

      ~ root_block_device {
          ~ delete_on_termination = true -> (known after apply)
          ~ device_name           = "/dev/xvda" -> (known after apply)
          ~ encrypted             = false -> (known after apply)
          ~ iops                  = 100 -> (known after apply)
          + kms_key_id            = (known after apply)
          ~ volume_id             = "***************" -> (known after apply)
          ~ volume_size           = 8 -> (known after apply)
          ~ volume_type           = "gp2" -> (known after apply)
        }

      - timeouts {}
    }

Plan: 1 to add, 0 to change, 1 to destroy.

Terraform Configuration Files

resource "aws_instance" "instance-01" {
  ami           = "*******************"
  instance_type = "t2.micro"

  network_interface {
    network_interface_id = "******************"
    device_index         = 0
  }

  tags = {
    Name = "instance-01"
  }
}

Steps to Reproduce

Step 1: create instance Step 2: import instance using command : terraform import aws_instance.instance-01 Step 3: terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

https://github.com/hashicorp/terraform-provider-aws/issues/1446

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 1 year ago

Hey @rutujachaudhari124 👋 Thank you for taking the time to raise this! It looks like you're using a fairly old version of both Terraform core and the AWS Provider. Are you able to test on a more recent version to verify if the import is successful?

rutujachaudhari124 commented 1 year ago

yes, I have checked in the latest version (4.60.0), still could not resolve this issue. The network interface is still not added to state file.

danilobovo commented 3 weeks ago

I'm using the latest version of terraform provider (v5.64.0) and the issue still occurring.