Skip to content

Commit a7d0df8

Browse files
authored
Merge pull request #43967 from tabito-hara/f-aws_vpc_ipam-add_metered_account
[Enhancement] aws_vpc_ipam: Add `metered_account` argument
2 parents 4dbb03a + f02d26b commit a7d0df8

File tree

7 files changed

+83
-0
lines changed

7 files changed

+83
-0
lines changed

.changelog/43967.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_vpc_ipam: Add `metered_account` argument
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_vpc_ipam: Add `metered_account` attribute
7+
```

internal/service/ec2/vpc_ipam.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ func resourceIPAM() *schema.Resource {
7272
Optional: true,
7373
Default: false,
7474
},
75+
"metered_account": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Computed: true,
79+
ValidateDiagFunc: enum.Validate[awstypes.IpamMeteredAccount](),
80+
},
7581
"operating_regions": {
7682
Type: schema.TypeSet,
7783
Required: true,
@@ -145,6 +151,10 @@ func resourceIPAMCreate(ctx context.Context, d *schema.ResourceData, meta any) d
145151
input.EnablePrivateGua = aws.Bool(v.(bool))
146152
}
147153

154+
if v, ok := d.GetOk("metered_account"); ok {
155+
input.MeteredAccount = awstypes.IpamMeteredAccount(v.(string))
156+
}
157+
148158
if v, ok := d.GetOk("tier"); ok {
149159
input.Tier = awstypes.IpamTier(v.(string))
150160
}
@@ -185,6 +195,7 @@ func resourceIPAMRead(ctx context.Context, d *schema.ResourceData, meta any) dia
185195
d.Set("default_resource_discovery_id", ipam.DefaultResourceDiscoveryId)
186196
d.Set(names.AttrDescription, ipam.Description)
187197
d.Set("enable_private_gua", ipam.EnablePrivateGua)
198+
d.Set("metered_account", ipam.MeteredAccount)
188199
if err := d.Set("operating_regions", flattenIPAMOperatingRegions(ipam.OperatingRegions)); err != nil {
189200
return sdkdiag.AppendErrorf(diags, "setting operating_regions: %s", err)
190201
}
@@ -215,6 +226,10 @@ func resourceIPAMUpdate(ctx context.Context, d *schema.ResourceData, meta any) d
215226
input.EnablePrivateGua = aws.Bool(d.Get("enable_private_gua").(bool))
216227
}
217228

229+
if d.HasChange("metered_account") {
230+
input.MeteredAccount = awstypes.IpamMeteredAccount(d.Get("metered_account").(string))
231+
}
232+
218233
if d.HasChange("operating_regions") {
219234
o, n := d.GetChange("operating_regions")
220235
if o == nil {

internal/service/ec2/vpc_ipam_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func (d *ipamDataSource) Schema(ctx context.Context, request datasource.SchemaRe
4545
"enable_private_gua": schema.BoolAttribute{
4646
Computed: true,
4747
},
48+
"metered_account": schema.StringAttribute{
49+
Computed: true,
50+
},
4851
names.AttrID: schema.StringAttribute{
4952
Required: true,
5053
},
@@ -124,6 +127,7 @@ type ipamModel struct {
124127
IpamARN types.String `tfsdk:"arn"`
125128
IpamID types.String `tfsdk:"id"`
126129
IpamRegion types.String `tfsdk:"ipam_region"`
130+
MeteredAccount types.String `tfsdk:"metered_account"`
127131
OperatingRegions fwtypes.ListNestedObjectValueOf[ipamOperatingRegionModel] `tfsdk:"operating_regions"`
128132
OwnerID types.String `tfsdk:"owner_id"`
129133
PrivateDefaultScopeID types.String `tfsdk:"private_default_scope_id"`

internal/service/ec2/vpc_ipam_data_source_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestAccIPAMDataSource_basic(t *testing.T) { // nosemgrep:ci.vpc-in-test-nam
3333
resource.TestCheckResourceAttrPair(dataSourceName, "default_resource_discovery_id", resourceName, "default_resource_discovery_id"),
3434
resource.TestCheckResourceAttrPair(dataSourceName, "default_resource_discovery_association_id", resourceName, "default_resource_discovery_association_id"),
3535
resource.TestCheckResourceAttrPair(dataSourceName, "enable_private_gua", resourceName, "enable_private_gua"),
36+
resource.TestCheckResourceAttrPair(dataSourceName, "metered_account", resourceName, "metered_account"),
3637
resource.TestCheckResourceAttrPair(dataSourceName, "operating_regions.0.region_name", resourceName, "operating_regions.0.region_name"),
3738
resource.TestCheckResourceAttrPair(dataSourceName, "private_default_scope_id", resourceName, "private_default_scope_id"),
3839
resource.TestCheckResourceAttrPair(dataSourceName, "public_default_scope_id", resourceName, "public_default_scope_id"),

internal/service/ec2/vpc_ipam_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
1616
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
17+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1718
"github.com/hashicorp/terraform-plugin-testing/terraform"
1819
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
1920
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -40,6 +41,7 @@ func TestAccIPAM_basic(t *testing.T) { // nosemgrep:ci.vpc-in-test-name
4041
acctest.CheckResourceAttrGlobalARNFormat(ctx, resourceName, names.AttrARN, "ec2", "ipam/{id}"),
4142
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, ""),
4243
resource.TestCheckResourceAttr(resourceName, "enable_private_gua", acctest.CtFalse),
44+
resource.TestCheckResourceAttr(resourceName, "metered_account", string(awstypes.IpamMeteredAccountIpamOwner)),
4345
resource.TestCheckResourceAttr(resourceName, "operating_regions.#", "1"),
4446
resource.TestCheckResourceAttr(resourceName, "scope_count", "2"),
4547
resource.TestMatchResourceAttr(resourceName, "private_default_scope_id", regexache.MustCompile(`^ipam-scope-[0-9a-f]+`)),
@@ -297,6 +299,45 @@ func TestAccIPAM_enablePrivateGUA(t *testing.T) { // nosemgrep:ci.vpc-in-test-na
297299
})
298300
}
299301

302+
func TestAccIPAM_meteredAccount(t *testing.T) { // nosemgrep:ci.vpc-in-test-name
303+
ctx := acctest.Context(t)
304+
var ipam awstypes.Ipam
305+
resourceName := "aws_vpc_ipam.test"
306+
307+
resource.ParallelTest(t, resource.TestCase{
308+
PreCheck: func() { acctest.PreCheck(ctx, t) },
309+
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
310+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
311+
CheckDestroy: testAccCheckIPAMDestroy(ctx),
312+
Steps: []resource.TestStep{
313+
{
314+
Config: testAccIPAMConfig_meteredAccount(string(awstypes.IpamMeteredAccountIpamOwner)),
315+
Check: resource.ComposeTestCheckFunc(
316+
testAccCheckIPAMExists(ctx, resourceName, &ipam),
317+
resource.TestCheckResourceAttr(resourceName, "metered_account", string(awstypes.IpamMeteredAccountIpamOwner)),
318+
),
319+
},
320+
{
321+
ResourceName: resourceName,
322+
ImportState: true,
323+
ImportStateVerify: true,
324+
},
325+
{
326+
Config: testAccIPAMConfig_meteredAccount(string(awstypes.IpamMeteredAccountResourceOwner)),
327+
ConfigPlanChecks: resource.ConfigPlanChecks{
328+
PreApply: []plancheck.PlanCheck{
329+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
330+
},
331+
},
332+
Check: resource.ComposeTestCheckFunc(
333+
testAccCheckIPAMExists(ctx, resourceName, &ipam),
334+
resource.TestCheckResourceAttr(resourceName, "metered_account", string(awstypes.IpamMeteredAccountResourceOwner)),
335+
),
336+
},
337+
},
338+
})
339+
}
340+
300341
func testAccCheckIPAMExists(ctx context.Context, n string, v *awstypes.Ipam) resource.TestCheckFunc {
301342
return func(s *terraform.State) error {
302343
rs, ok := s.RootModule().Resources[n]
@@ -472,3 +513,16 @@ resource "aws_vpc_ipam" "test" {
472513
}
473514
`, enablePrivateGUA)
474515
}
516+
517+
func testAccIPAMConfig_meteredAccount(meteredAccount string) string {
518+
return fmt.Sprintf(`
519+
data "aws_region" "current" {}
520+
521+
resource "aws_vpc_ipam" "test" {
522+
operating_regions {
523+
region_name = data.aws_region.current.region
524+
}
525+
metered_account = %[1]q
526+
}
527+
`, meteredAccount)
528+
}

website/docs/d/vpc_ipam.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ This data source exports the following attributes in addition to the arguments a
3838
* `enable_private_gua` - If private GUA is enabled.
3939
* `id` - ID of the IPAM resource.
4040
* `ipam_region` - Region that the IPAM exists in.
41+
* `metered_account` - AWS account that is charged for active IP addresses managed in IPAM.
4142
* `operating_regions` - Regions that the IPAM is configured to operate in.
4243
* `owner_id` - ID of the account that owns this IPAM.
4344
* `private_default_scope_id` - ID of the default private scope.

website/docs/r/vpc_ipam.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ This resource supports the following arguments:
6363
* `cascade` - (Optional) Enables you to quickly delete an IPAM, private scopes, pools in private scopes, and any allocations in the pools in private scopes.
6464
* `description` - (Optional) A description for the IPAM.
6565
* `enable_private_gua` - (Optional) Enable this option to use your own GUA ranges as private IPv6 addresses. Default: `false`.
66+
* `metered_account` - (Optional) AWS account that is charged for active IP addresses managed in IPAM. Valid values are `ipam-owner` (default) and `resource-owner`.
6667
* `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.
6768
* `tier` - (Optional) specifies the IPAM tier. Valid options include `free` and `advanced`. Default is `advanced`.
6869
* `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.

0 commit comments

Comments
 (0)