Skip to content

Commit

Permalink
Merge pull request #36504 from mmourick/f/add-tier-argument-to-vpc-ip…
Browse files Browse the repository at this point in the history
…am-resource

Add `tier` argument to `aws_vpc_ipam` resource
  • Loading branch information
ewbankkit committed Mar 25, 2024
2 parents 0ab9145 + 673540a commit 5ade1b8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/36504.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_vpc_ipam: Add `tier` argument
```
16 changes: 16 additions & 0 deletions internal/service/ec2/ipam_.go
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"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/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -91,6 +92,12 @@ func ResourceIPAM() *schema.Resource {
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"tier": {
Type: schema.TypeString,
Optional: true,
Default: ec2.IpamTierAdvanced,
ValidateFunc: validation.StringInSlice(ec2.IpamTier_Values(), false),
},
},

CustomizeDiff: customdiff.Sequence(
Expand Down Expand Up @@ -128,6 +135,10 @@ func resourceIPAMCreate(ctx context.Context, d *schema.ResourceData, meta interf
input.Description = aws.String(v.(string))
}

if v, ok := d.GetOk("tier"); ok {
input.Tier = aws.String(v.(string))
}

output, err := conn.CreateIpamWithContext(ctx, input)

if err != nil {
Expand Down Expand Up @@ -169,6 +180,7 @@ func resourceIPAMRead(ctx context.Context, d *schema.ResourceData, meta interfac
d.Set("public_default_scope_id", ipam.PublicDefaultScopeId)
d.Set("private_default_scope_id", ipam.PrivateDefaultScopeId)
d.Set("scope_count", ipam.ScopeCount)
d.Set("tier", ipam.Tier)

setTagsOut(ctx, ipam.Tags)

Expand Down Expand Up @@ -211,6 +223,10 @@ func resourceIPAMUpdate(ctx context.Context, d *schema.ResourceData, meta interf
}
}

if d.HasChange("tier") {
input.Tier = aws.String(d.Get("tier").(string))
}

_, err := conn.ModifyIpamWithContext(ctx, input)

if err != nil {
Expand Down
49 changes: 48 additions & 1 deletion internal/service/ec2/ipam_test.go
Expand Up @@ -176,7 +176,41 @@ func TestAccIPAM_cascade(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"cascade"},
ImportStateVerifyIgnore: []string{"cascade", "scope_count"},
},
},
})
}

func TestAccIPAM_tier(t *testing.T) {
ctx := acctest.Context(t)
var ipam ec2.Ipam
resourceName := "aws_vpc_ipam.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckIPAMDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccIPAMConfig_tier("free"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIPAMExists(ctx, resourceName, &ipam),
resource.TestCheckResourceAttr(resourceName, "tier", "free"),
),
},
{
Config: testAccIPAMConfig_tier("advanced"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIPAMExists(ctx, resourceName, &ipam),
resource.TestCheckResourceAttr(resourceName, "tier", "advanced"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
Expand Down Expand Up @@ -378,3 +412,16 @@ resource "aws_vpc_ipam" "test" {
}
`, tagKey1, tagValue1, tagKey2, tagValue2)
}

func testAccIPAMConfig_tier(tier string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
resource "aws_vpc_ipam" "test" {
operating_regions {
region_name = data.aws_region.current.name
}
tier = "%s"
}
`, tier)
}
3 changes: 2 additions & 1 deletion website/docs/r/vpc_ipam.html.markdown
Expand Up @@ -59,10 +59,11 @@ locals {

This resource supports the following arguments:

* `cascade` - (Optional) Enables you to quickly delete an IPAM, private scopes, pools in private scopes, and any allocations in the pools in private scopes.
* `description` - (Optional) A description for the IPAM.
* `operating_regions` - (Required) Determines which locales can be chosen when you create pools. 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. You specify a region using the [region_name](#operating_regions) parameter. You **must** set your provider block region as an operating_region.
* `tier` - (Optional) specifies the IPAM tier. Valid options include `free` and `advanced`. Default is `advanced`.
* `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.
* `cascade` - (Optional) Enables you to quickly delete an IPAM, private scopes, pools in private scopes, and any allocations in the pools in private scopes.

### operating_regions

Expand Down

0 comments on commit 5ade1b8

Please sign in to comment.