From ab054c237e0685b326629bd23de7230b7cd8de03 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 8 Oct 2024 17:10:09 -0400 Subject: [PATCH] r/aws_vpc_ipam_pool: Use IpamScopeType to determine whether to send PubliclyAdvertisable. --- internal/service/ec2/ipam_pool.go | 15 ++++++++++----- internal/service/ec2/ipam_pool_test.go | 26 +++++++++++++------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/internal/service/ec2/ipam_pool.go b/internal/service/ec2/ipam_pool.go index 08e9d8fb30a..290f5453923 100644 --- a/internal/service/ec2/ipam_pool.go +++ b/internal/service/ec2/ipam_pool.go @@ -153,11 +153,18 @@ func resourceIPAMPoolCreate(ctx context.Context, d *schema.ResourceData, meta in var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EC2Client(ctx) + scopeID := d.Get("ipam_scope_id").(string) + scope, err := findIPAMScopeByID(ctx, conn, scopeID) + + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading IPAM Scope (%s): %s", scopeID, err) + } + addressFamily := awstypes.AddressFamily(d.Get("address_family").(string)) input := &ec2.CreateIpamPoolInput{ AddressFamily: addressFamily, ClientToken: aws.String(id.UniqueId()), - IpamScopeId: aws.String(d.Get("ipam_scope_id").(string)), + IpamScopeId: aws.String(scopeID), TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeIpamPool), } @@ -193,14 +200,12 @@ func resourceIPAMPoolCreate(ctx context.Context, d *schema.ResourceData, meta in input.AwsService = awstypes.IpamPoolAwsService(v.(string)) } - var publicIPSource awstypes.IpamPoolPublicIpSource if v, ok := d.GetOk("public_ip_source"); ok { - publicIPSource = awstypes.IpamPoolPublicIpSource(v.(string)) - input.PublicIpSource = publicIPSource + input.PublicIpSource = awstypes.IpamPoolPublicIpSource(v.(string)) } // PubliclyAdvertisable must be set if if the AddressFamily is IPv6 and PublicIpSource is byoip. // The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip. - if addressFamily == awstypes.AddressFamilyIpv6 && publicIPSource != awstypes.IpamPoolPublicIpSourceAmazon { + if addressFamily == awstypes.AddressFamilyIpv6 && scope.IpamScopeType == awstypes.IpamScopeTypePublic { input.PubliclyAdvertisable = aws.Bool(d.Get("publicly_advertisable").(bool)) } diff --git a/internal/service/ec2/ipam_pool_test.go b/internal/service/ec2/ipam_pool_test.go index 749ba3be707..ca3ff469ade 100644 --- a/internal/service/ec2/ipam_pool_test.go +++ b/internal/service/ec2/ipam_pool_test.go @@ -306,6 +306,19 @@ func testAccCheckIPAMPoolDestroy(ctx context.Context) resource.TestCheckFunc { } } +func testAccCheckIPAMPoolCIDRCreate(ctx context.Context, ipampool *awstypes.IpamPool) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) + + _, err := conn.ProvisionIpamPoolCidr(ctx, &ec2.ProvisionIpamPoolCidrInput{ + IpamPoolId: ipampool.IpamPoolId, + Cidr: aws.String("10.0.0.0/16"), + }) + + return err + } +} + const testAccIPAMPoolConfig_base = ` data "aws_region" "current" {} @@ -366,19 +379,6 @@ resource "aws_vpc_ipam_pool" "test" { } `) -func testAccCheckIPAMPoolCIDRCreate(ctx context.Context, ipampool *awstypes.IpamPool) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Client(ctx) - - _, err := conn.ProvisionIpamPoolCidr(ctx, &ec2.ProvisionIpamPoolCidrInput{ - IpamPoolId: ipampool.IpamPoolId, - Cidr: aws.String("10.0.0.0/16"), - }) - - return err - } -} - func testAccIPAMPoolConfig_tags(tagKey1, tagValue1 string) string { return acctest.ConfigCompose(testAccIPAMPoolConfig_base, fmt.Sprintf(` resource "aws_vpc_ipam_pool" "test" {