Skip to content

Commit

Permalink
r/aws_vpc_ipam_pool: Use IpamScopeType to determine whether to send P…
Browse files Browse the repository at this point in the history
…ubliclyAdvertisable.
  • Loading branch information
ewbankkit committed Oct 8, 2024
1 parent 8dbd50e commit ab054c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
15 changes: 10 additions & 5 deletions internal/service/ec2/ipam_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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))
}

Expand Down
26 changes: 13 additions & 13 deletions internal/service/ec2/ipam_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit ab054c2

Please sign in to comment.