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

Add tier argument to aws_vpc_ipam resource #36504

Merged
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/36504.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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{
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
{
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
Original file line number Diff line number Diff line change
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
Loading