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.84k stars 9.19k forks source link

ipam_pool: Fix publicly_advertisable bug #40042

Closed YakDriver closed 1 week ago

YakDriver commented 1 week ago

Description

At the moment, public_advertisable is being sent to AWS when it shouldn't in certain cases. The current logic isn't checking the public_ip_source so where ipv6, public scope, and public_ip_source = "amazon", it will include public_advertisable 😱 :

if addressFamily == awstypes.AddressFamilyIpv6 && scope.IpamScopeType == awstypes.IpamScopeTypePublic {
    input.PubliclyAdvertisable = aws.Bool(d.Get("publicly_advertisable").(bool))
}

Before that, pre #39600, the logic was wrong in a different way. It would include public_advertisable where ipv6 and the public_ip_source was not "amazon" indicating BYOIP, by either not using public_ip_source or explicitly setting "byoip". This would erroneously include non-public scope.

if addressFamily == awstypes.AddressFamilyIpv6 && publicIpSource != awstypes.IpamPoolPublicIpSourceAmazon {
    input.PubliclyAdvertisable = aws.Bool(d.Get("publicly_advertisable").(bool))
}

The fix is to check all three things before setting publicly_advertisable: ipv6, public scope, and source is not Amazon.

Relations

Closes #39967 Relates #39600

References

Output from Acceptance Testing

% make t T=TestAccIPAMPool_ K=ec2
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.23.2 test ./internal/service/ec2/... -v -count 1 -parallel 20 -run='TestAccIPAMPool_'  -timeout 360m
2024/11/07 13:06:07 Initializing Terraform AWS Provider...
=== RUN   TestAccIPAMPool_basic
=== PAUSE TestAccIPAMPool_basic
=== RUN   TestAccIPAMPool_disappears
=== PAUSE TestAccIPAMPool_disappears
=== RUN   TestAccIPAMPool_ipv6Basic
=== PAUSE TestAccIPAMPool_ipv6Basic
=== RUN   TestAccIPAMPool_ipv6PublicIPAmazon
=== PAUSE TestAccIPAMPool_ipv6PublicIPAmazon
=== RUN   TestAccIPAMPool_ipv6Contiguous
=== PAUSE TestAccIPAMPool_ipv6Contiguous
=== RUN   TestAccIPAMPool_cascade
=== PAUSE TestAccIPAMPool_cascade
=== RUN   TestAccIPAMPool_tags
=== PAUSE TestAccIPAMPool_tags
=== RUN   TestAccIPAMPool_ipv6PrivateScope
=== PAUSE TestAccIPAMPool_ipv6PrivateScope
=== CONT  TestAccIPAMPool_basic
=== CONT  TestAccIPAMPool_ipv6Contiguous
=== CONT  TestAccIPAMPool_ipv6Basic
=== CONT  TestAccIPAMPool_disappears
=== CONT  TestAccIPAMPool_tags
=== CONT  TestAccIPAMPool_ipv6PrivateScope
=== CONT  TestAccIPAMPool_ipv6PublicIPAmazon
=== CONT  TestAccIPAMPool_cascade
--- PASS: TestAccIPAMPool_ipv6Contiguous (46.28s)
--- PASS: TestAccIPAMPool_ipv6Basic (46.29s)
--- PASS: TestAccIPAMPool_ipv6PublicIPAmazon (46.59s)
--- PASS: TestAccIPAMPool_ipv6PrivateScope (47.24s)
--- PASS: TestAccIPAMPool_disappears (49.52s)
--- PASS: TestAccIPAMPool_basic (58.06s)
--- PASS: TestAccIPAMPool_tags (68.01s)
--- PASS: TestAccIPAMPool_cascade (68.63s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/ec2    72.765s
github-actions[bot] commented 1 week ago

Community Note

Voting for Prioritization

For Submitters

github-actions[bot] commented 4 days ago

This functionality has been released in v5.75.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!