Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipam_pool: Fix publicly_advertisable bug #40042

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/40042.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_vpc_ipam_pool: Fix bug when `public_ip_source = "amazon"`: `The request can only contain PubliclyAdvertisable if the AddressFamily is IPv6 and PublicIpSource is byoip.`
```
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ jobs:
# Trigger garbage collection more frequently to reduce the likelihood
# of OOM errors. Higher values mean it runs faster but more likely to OOM, exit 137.
# ref: https://golangci-lint.run/product/performance/
GOGC: "150" # 100 is the default value
GOGC: "140" # 100 is the default value
17 changes: 9 additions & 8 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,9 +199,15 @@ 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))
}
// 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 && scope.IpamScopeType == awstypes.IpamScopeTypePublic {

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 {
input.PubliclyAdvertisable = aws.Bool(d.Get("publicly_advertisable").(bool))
}

Expand Down
40 changes: 40 additions & 0 deletions internal/service/ec2/ipam_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ func TestAccIPAMPool_ipv6Basic(t *testing.T) {
})
}

func TestAccIPAMPool_ipv6PublicIPAmazon(t *testing.T) {
ctx := acctest.Context(t)
var pool awstypes.IpamPool
resourceName := "aws_vpc_ipam_pool.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckIPAMPoolDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccIPAMPoolConfig_ipv6PublicIPAmazon,
Check: resource.ComposeTestCheckFunc(
testAccCheckIPAMPoolExists(ctx, resourceName, &pool),
resource.TestCheckResourceAttr(resourceName, "address_family", "ipv6"),
resource.TestCheckResourceAttr(resourceName, "public_ip_source", "amazon"),
resource.TestCheckResourceAttr(resourceName, "aws_service", "ec2"),
resource.TestCheckResourceAttr(resourceName, "publicly_advertisable", acctest.CtFalse),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccIPAMPool_ipv6Contiguous(t *testing.T) {
ctx := acctest.Context(t)
var pool awstypes.IpamPool
Expand Down Expand Up @@ -368,6 +398,16 @@ resource "aws_vpc_ipam_pool" "test" {
}
`)

var testAccIPAMPoolConfig_ipv6PublicIPAmazon = acctest.ConfigCompose(testAccIPAMPoolConfig_base, `
resource "aws_vpc_ipam_pool" "test" {
address_family = "ipv6"
ipam_scope_id = aws_vpc_ipam.test.public_default_scope_id
locale = data.aws_region.current.name
public_ip_source = "amazon"
aws_service = "ec2"
}
`)

var testAccIPAMPoolConfig_ipv6Contiguous = acctest.ConfigCompose(testAccIPAMPoolConfig_base, `
resource "aws_vpc_ipam_pool" "test" {
address_family = "ipv6"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/vpc_ipam_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ within the CIDR range in the pool.
* `description` - (Optional) A description for the IPAM pool.
* `ipam_scope_id` - (Required) The ID of the scope in which you would like to create the IPAM pool.
* `locale` - (Optional) The locale in which you would like to create the IPAM pool. Locale is the Region where you want to make an IPAM pool available for allocations. You can only create pools with locales that match the operating Regions of the IPAM. You can only create VPCs from a pool whose locale matches the VPC's Region. Possible values: Any AWS region, such as `us-east-1`.
* `publicly_advertisable` - (Optional) Defines whether or not IPv6 pool space is publicly advertisable over the internet. This argument is required if `address_family = "ipv6"` and `public_ip_source = "byoip"`, default is `false`. This option is not available for IPv4 pool space or if `public_ip_source = "amazon"`.
* `publicly_advertisable` - (Optional) Defines whether or not IPv6 pool space is publicly advertisable over the internet. This argument is required if `address_family = "ipv6"` and `public_ip_source = "byoip"`, default is `false`. This option is not available for IPv4 pool space or if `public_ip_source = "amazon"`. Setting this argument to `true` when it is not available may result in erroneous differences being reported.
* `public_ip_source` - (Optional) The IP address source for pools in the public scope. Only used for provisioning IP address CIDRs to pools in the public scope. Valid values are `byoip` or `amazon`. Default is `byoip`.
* `source_ipam_pool_id` - (Optional) The ID of the source IPAM pool. Use this argument to create a child pool within an existing pool.
* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
Expand Down
Loading