Skip to content

Commit

Permalink
Merge pull request #22501 from GlennChia/f-aws_vpc_ipam_preview_next_…
Browse files Browse the repository at this point in the history
…cidr-new-attribute

r/aws_vpc_ipam_preview_next_cidr - new attribute
  • Loading branch information
ewbankkit authored Jan 10, 2022
2 parents 933ba4c + c4fde32 commit f7264b5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .changelog/22501.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_vpc_ipam_preview_next_cidr: Add `disallowed_cidrs` argument
```
37 changes: 18 additions & 19 deletions internal/service/ec2/vpc_ipam_preview_next_cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
// "github.com/hashicorp/terraform-provider-aws/internal/flex"
// "github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

func ResourceVPCIpamPreviewNextCidr() *schema.Resource {
Expand All @@ -24,20 +24,19 @@ func ResourceVPCIpamPreviewNextCidr() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
// // temp comment out till bug is resolved
// "disallowed_cidrs": {
// Type: schema.TypeSet,
// Optional: true,
// ForceNew: true,
// Elem: &schema.Schema{
// Type: schema.TypeString,
// ValidateFunc: validation.Any(
// verify.ValidIPv4CIDRNetworkAddress,
// // Follow the numbers used for netmask_length
// validation.IsCIDRNetwork(0, 32),
// ),
// },
// },
"disallowed_cidrs": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.Any(
verify.ValidIPv4CIDRNetworkAddress,
// Follow the numbers used for netmask_length
validation.IsCIDRNetwork(0, 32),
),
},
},
"ipam_pool_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -70,9 +69,9 @@ func resourceVPCIpamPreviewNextCidrCreate(d *schema.ResourceData, meta interface
PreviewNextCidr: aws.Bool(true),
}

// if v, ok := d.GetOk("disallowed_cidrs"); ok && v.(*schema.Set).Len() > 0 {
// input.DisallowedCidrs = flex.ExpandStringSet(v.(*schema.Set))
// }
if v, ok := d.GetOk("disallowed_cidrs"); ok && v.(*schema.Set).Len() > 0 {
input.DisallowedCidrs = flex.ExpandStringSet(v.(*schema.Set))
}

if v, ok := d.GetOk("netmask_length"); ok {
input.NetmaskLength = aws.Int64(int64(v.(int)))
Expand Down
85 changes: 42 additions & 43 deletions internal/service/ec2/vpc_ipam_preview_next_cidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,32 @@ func TestAccVPCIpamPreviewNextCidr_ipv4Allocated(t *testing.T) {
})
}

// // temp comment out till bug is resolved
// func TestAccVPCIpamPreviewNextCidr_ipv4DisallowedCidr(t *testing.T) {
// resourceName := "aws_vpc_ipam_preview_next_cidr.test"
// disallowedCidr := "172.2.0.0/32"
// netmaskLength := "28"

// resource.ParallelTest(t, resource.TestCase{
// PreCheck: func() { acctest.PreCheck(t); testAccIPAMPreCheck(t) },
// ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
// Providers: acctest.Providers,
// CheckDestroy: nil,
// Steps: []resource.TestStep{
// {
// Config: testAccVPCIpamPreviewNextCidrIpv4DisallowedCidr(netmaskLength, disallowedCidr),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttrSet(resourceName, "cidr"),
// resource.TestCheckResourceAttr(resourceName, "disallowed_cidrs.#", "1"),
// resource.TestCheckResourceAttr(resourceName, "disallowed_cidrs.0", disallowedCidr),
// resource.TestCheckResourceAttrSet(resourceName, "id"),
// resource.TestCheckResourceAttrPair(resourceName, "ipam_pool_id", "aws_vpc_ipam_pool.test", "id"),
// resource.TestCheckResourceAttr(resourceName, "netmask_length", netmaskLength),
// ),
// },
// },
// })
// }
func TestAccVPCIpamPreviewNextCidr_ipv4DisallowedCidr(t *testing.T) {
resourceName := "aws_vpc_ipam_preview_next_cidr.test"
disallowedCidr := "172.2.0.0/28"
netmaskLength := "28"
expectedCidr := "172.2.0.16/28"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccIPAMPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccVPCIpamPreviewNextCidrIpv4DisallowedCidr(netmaskLength, disallowedCidr),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "cidr", expectedCidr),
resource.TestCheckResourceAttr(resourceName, "disallowed_cidrs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "disallowed_cidrs.0", disallowedCidr),
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "ipam_pool_id", "aws_vpc_ipam_pool.test", "id"),
resource.TestCheckResourceAttr(resourceName, "netmask_length", netmaskLength),
),
},
},
})
}

const testAccVPCIpamPreviewNextCidrIpv4Base = `
data "aws_region" "current" {}
Expand Down Expand Up @@ -150,20 +150,19 @@ resource "aws_vpc_ipam_pool_cidr_allocation" "test" {
`, netmaskLength))
}

// // temp comment out till bug is resolved
// func testAccVPCIpamPreviewNextCidrIpv4DisallowedCidr(netmaskLength, disallowedCidr string) string {
// return testAccVPCIpamPreviewNextCidrIpv4Base + fmt.Sprintf(`
// resource "aws_vpc_ipam_preview_next_cidr" "test" {
// ipam_pool_id = aws_vpc_ipam_pool.test.id
// netmask_length = %[1]q

// disallowed_cidrs = [
// %[2]q
// ]

// depends_on = [
// aws_vpc_ipam_pool_cidr.test
// ]
// }
// `, netmaskLength, disallowedCidr)
// }
func testAccVPCIpamPreviewNextCidrIpv4DisallowedCidr(netmaskLength, disallowedCidr string) string {
return testAccVPCIpamPreviewNextCidrIpv4Base + fmt.Sprintf(`
resource "aws_vpc_ipam_preview_next_cidr" "test" {
ipam_pool_id = aws_vpc_ipam_pool.test.id
netmask_length = %[1]q
disallowed_cidrs = [
%[2]q
]
depends_on = [
aws_vpc_ipam_pool_cidr.test
]
}
`, netmaskLength, disallowedCidr)
}
5 changes: 5 additions & 0 deletions website/docs/r/vpc_ipam_preview_next_cidr.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ resource "aws_vpc_ipam_preview_next_cidr" "example" {
ipam_pool_id = aws_vpc_ipam_pool.example.id
netmask_length = 28
disallowed_cidrs = [
"172.2.0.0/32"
]
depends_on = [
aws_vpc_ipam_pool_cidr.example
]
Expand Down Expand Up @@ -48,6 +52,7 @@ resource "aws_vpc_ipam" "example" {

The following arguments are supported:

* `disallowed_cidrs` - (Optional) Exclude a particular CIDR range from being returned by the pool.
* `ipam_pool_id` - (Required) The ID of the pool to which you want to assign a CIDR.
* `netmask_length` - (Optional) The netmask length of the CIDR you would like to preview from the IPAM pool.

Expand Down

0 comments on commit f7264b5

Please sign in to comment.