Skip to content

Commit

Permalink
Merge pull request #36898 from nikhil-goenka/f-aws_vpc_ipam_pool
Browse files Browse the repository at this point in the history
f-aws_vpc_ipam_pool support for cascade
  • Loading branch information
jar-b authored Apr 16, 2024
2 parents 3401119 + 0b0ae28 commit a44a6b9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/36898.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_vpc_ipam_pool: Add `cascade` argument
```
16 changes: 13 additions & 3 deletions internal/service/ec2/ipam_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func ResourceIPAMPool() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice(ec2.IpamPoolAwsService_Values(), false),
},
"cascade": {
Type: schema.TypeBool,
Optional: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -315,10 +319,16 @@ func resourceIPAMPoolDelete(ctx context.Context, d *schema.ResourceData, meta in
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Conn(ctx)

log.Printf("[DEBUG] Deleting IPAM Pool: %s", d.Id())
_, err := conn.DeleteIpamPoolWithContext(ctx, &ec2.DeleteIpamPoolInput{
input := &ec2.DeleteIpamPoolInput{
IpamPoolId: aws.String(d.Id()),
})
}

if v, ok := d.GetOk("cascade"); ok {
input.Cascade = aws.Bool(v.(bool))
}

log.Printf("[DEBUG] Deleting IPAM Pool: %s", d.Id())
_, err := conn.DeleteIpamPoolWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, errCodeInvalidIPAMPoolIdNotFound) {
return diags
Expand Down
50 changes: 50 additions & 0 deletions internal/service/ec2/ipam_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand Down Expand Up @@ -159,6 +160,34 @@ func TestAccIPAMPool_ipv6Contiguous(t *testing.T) {
})
}

func TestAccIPAMPool_cascade(t *testing.T) {
ctx := acctest.Context(t)
var pool ec2.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_cascade,
Check: resource.ComposeTestCheckFunc(
testAccCheckIPAMPoolExists(ctx, resourceName, &pool),
testAccCheckIPAMPoolCIDRCreate(ctx, &pool),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cascade"},
},
},
})
}

func TestAccIPAMPool_tags(t *testing.T) {
ctx := acctest.Context(t)
var pool ec2.IpamPool
Expand Down Expand Up @@ -272,6 +301,14 @@ resource "aws_vpc_ipam_pool" "test" {
}
`)

var testAccIPAMPoolConfig_cascade = acctest.ConfigCompose(testAccIPAMPoolConfig_base, `
resource "aws_vpc_ipam_pool" "test" {
address_family = "ipv4"
ipam_scope_id = aws_vpc_ipam.test.private_default_scope_id
cascade = true
}
`)

var testAccIPAMPoolConfig_updated = acctest.ConfigCompose(testAccIPAMPoolConfig_base, `
resource "aws_vpc_ipam_pool" "test" {
address_family = "ipv4"
Expand Down Expand Up @@ -307,6 +344,19 @@ resource "aws_vpc_ipam_pool" "test" {
}
`)

func testAccCheckIPAMPoolCIDRCreate(ctx context.Context, ipampool *ec2.IpamPool) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn(ctx)

_, err := conn.ProvisionIpamPoolCidrWithContext(ctx, &ec2.ProvisionIpamPoolCidrInput{
IpamPoolId: aws.String(*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
1 change: 1 addition & 0 deletions website/docs/r/vpc_ipam_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This resource supports the following arguments:
* `auto_import` - (Optional) If you include this argument, IPAM automatically imports any VPCs you have in your scope that fall
within the CIDR range in the pool.
* `aws_service` - (Optional) Limits which AWS service the pool can be used in. Only useable on public scopes. Valid Values: `ec2`.
* `cascade` - (Optional) Enables you to quickly delete an IPAM pool and all resources within that pool, including provisioned CIDRs, allocations, and other pools.
* `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`.
Expand Down

0 comments on commit a44a6b9

Please sign in to comment.