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

f-aws_vpc_ipam_pool support for cascade #36898

Merged
merged 4 commits into from
Apr 16, 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/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
Loading