diff --git a/.changelog/36504.txt b/.changelog/36504.txt new file mode 100644 index 000000000000..4d6be18a9f20 --- /dev/null +++ b/.changelog/36504.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_vpc_ipam: Add `tier` argument +``` \ No newline at end of file diff --git a/internal/service/ec2/ipam_.go b/internal/service/ec2/ipam_.go index f47d90f11da3..4e81ad04a1f1 100644 --- a/internal/service/ec2/ipam_.go +++ b/internal/service/ec2/ipam_.go @@ -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" @@ -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( @@ -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 { @@ -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) @@ -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 { diff --git a/internal/service/ec2/ipam_test.go b/internal/service/ec2/ipam_test.go index 7b77815d4213..ce6dd94c48e5 100644 --- a/internal/service/ec2/ipam_test.go +++ b/internal/service/ec2/ipam_test.go @@ -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, }, }, }) @@ -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) +} diff --git a/website/docs/r/vpc_ipam.html.markdown b/website/docs/r/vpc_ipam.html.markdown index 4dc6140282ae..72723ed0f5ab 100644 --- a/website/docs/r/vpc_ipam.html.markdown +++ b/website/docs/r/vpc_ipam.html.markdown @@ -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