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.83k stars 9.18k forks source link

[Bug]: importing aws_vpc_ipv4_cidr_block_association does not set ipv4 optional values #38873

Open ejorgensen22 opened 3 months ago

ejorgensen22 commented 3 months ago

Terraform Core Version

1.7.5

AWS Provider Version

5.50.0

Affected Resource(s)

Expected Behavior

Should capture ipv4_ipam_pool_id and ipv4_netmask_length

Actual Behavior

Only captures cidr_blockand vpc_id are captured and after the import the resource is being forced to be replaced based on the code that includes ipv4_ipam_pool_id and ipv4_netmask_length.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

data "aws_region" "current" {}

resource "aws_vpc_ipam" "example" {
  operating_regions {
    region_name = data.aws_region.current.name
  }
}

resource "aws_vpc_ipam_pool" "example" {
  address_family = "ipv4"
  ipam_scope_id  = aws_vpc_ipam.example.private_default_scope_id
  locale         = data.aws_region.current.name
}

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_vpc_ipv4_cidr_block_association" "secondary_cidr" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "172.20.0.0/16"
  ipv4_ipam_pool_id = aws_vpc_ipam_pool.example.id
  ipv4_netmask_length = 16
}

Steps to Reproduce

  1. Use example to create ipam pool and vpc_ipv4_cidr_block_association.
  2. terraform state show for vpc_ipv4_cidr_block_association to show state
  3. terraform state rm to remove the vpc_ipv4_cidr_block_association from state file
  4. terraform import aws_vpc_ipv4_cidr_block_association.example vpc-cidr-assoc-xxxxxxxx to import to state
  5. terraform state show for vpc_ipv4_cidr_block_association to show state

Output from step 5 should include missing fields

Debug Output

No response

Panic Output

No response

Important Factoids

I am not familiar enough with the code but I believe the gap to be that the read function does not set these fields. https://github.com/hashicorp/terraform-provider-aws/blob/fa57128f951048f704869c12f0e8ef7289da3860/internal/service/ec2/vpc_ipv4_cidr_block_association.go#L130-L134

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue