Skip to content

Commit

Permalink
ipam_pool: Move declaration to when used
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Nov 7, 2024
1 parent 9208140 commit 37b97bf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/service/ec2/ipam_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ func resourceIPAMPoolCreate(ctx context.Context, d *schema.ResourceData, meta in
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{
Expand Down Expand Up @@ -204,6 +199,12 @@ func resourceIPAMPoolCreate(ctx context.Context, d *schema.ResourceData, meta in
if v, ok := d.GetOk("public_ip_source"); ok {
input.PublicIpSource = awstypes.IpamPoolPublicIpSource(v.(string))
}

scope, err := findIPAMScopeByID(ctx, conn, scopeID)
if err != nil {
return sdkdiag.AppendErrorf(diags, "reading IPAM Scope (%s): %s", scopeID, err)
}

// PubliclyAdvertisable must be set if if the AddressFamily is IPv6 and PublicIpSource is byoip (either '' or 'byoip').
// The request can't contain PubliclyAdvertisable if PublicIpSource is 'amazon'.
if addressFamily == awstypes.AddressFamilyIpv6 && scope.IpamScopeType == awstypes.IpamScopeTypePublic && input.PublicIpSource != awstypes.IpamPoolPublicIpSourceAmazon {
Expand Down

0 comments on commit 37b97bf

Please sign in to comment.