Skip to content

Commit b1f8548

Browse files
authored
Merge pull request #44560 from alexanderldavis/f-aws_vpclattice_resource_gateway-add_ipv4_addresses_per_eni
[Enhancement]: `aws_vpclattice_resource_gateway`: add `ipv4_addresses_per_eni` argument
2 parents 48d7d7d + 75a7c7d commit b1f8548

File tree

4 files changed

+84
-11
lines changed

4 files changed

+84
-11
lines changed

.changelog/44560.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_vpclattice_resource_gateway: Add `ipv4_addresses_per_eni` argument
3+
```

internal/service/vpclattice/resource_gateway.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import (
1212
"github.com/aws/aws-sdk-go-v2/service/vpclattice"
1313
awstypes "github.com/aws/aws-sdk-go-v2/service/vpclattice/types"
1414
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
15+
"github.com/hashicorp/terraform-plugin-framework-validators/int32validator"
1516
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1617
"github.com/hashicorp/terraform-plugin-framework/path"
1718
"github.com/hashicorp/terraform-plugin-framework/resource"
1819
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
20+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
1921
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2022
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
2123
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -67,6 +69,18 @@ func (r *resourceGatewayResource) Schema(ctx context.Context, request resource.S
6769
stringplanmodifier.UseStateForUnknown(),
6870
},
6971
},
72+
"ipv4_addresses_per_eni": schema.Int32Attribute{
73+
Optional: true,
74+
Computed: true,
75+
Validators: []validator.Int32{
76+
int32validator.AtLeast(1),
77+
int32validator.AtMost(62),
78+
},
79+
PlanModifiers: []planmodifier.Int32{
80+
int32planmodifier.RequiresReplace(),
81+
int32planmodifier.UseStateForUnknown(),
82+
},
83+
},
7084
names.AttrName: schema.StringAttribute{
7185
Required: true,
7286
Validators: []validator.String{
@@ -136,6 +150,11 @@ func (r *resourceGatewayResource) Create(ctx context.Context, request resource.C
136150
input.Tags = getTagsIn(ctx)
137151
input.VpcIdentifier = fwflex.StringFromFramework(ctx, data.VPCID)
138152

153+
// Ipv4AddressesPerEni is irrelevant if IPAddressType is IPv6
154+
if data.IPAddressType.ValueEnum() != awstypes.ResourceGatewayIpAddressTypeIpv6 {
155+
input.Ipv4AddressesPerEni = fwflex.Int32FromFramework(ctx, data.IPV4AddressesPerEni)
156+
}
157+
139158
outputCRG, err := conn.CreateResourceGateway(ctx, &input)
140159

141160
if err != nil {
@@ -354,15 +373,16 @@ func waitResourceGatewayDeleted(ctx context.Context, conn *vpclattice.Client, id
354373

355374
type resourceGatewayResourceModel struct {
356375
framework.WithRegionModel
357-
ARN types.String `tfsdk:"arn"`
358-
ID types.String `tfsdk:"id"`
359-
IPAddressType fwtypes.StringEnum[awstypes.ResourceGatewayIpAddressType] `tfsdk:"ip_address_type"`
360-
Name types.String `tfsdk:"name"`
361-
SecurityGroupIDs fwtypes.SetOfString `tfsdk:"security_group_ids"`
362-
Status fwtypes.StringEnum[awstypes.ResourceGatewayStatus] `tfsdk:"status"`
363-
SubnetIDs fwtypes.SetOfString `tfsdk:"subnet_ids"`
364-
Tags tftags.Map `tfsdk:"tags"`
365-
TagsAll tftags.Map `tfsdk:"tags_all"`
366-
Timeouts timeouts.Value `tfsdk:"timeouts"`
367-
VPCID types.String `tfsdk:"vpc_id"`
376+
ARN types.String `tfsdk:"arn"`
377+
ID types.String `tfsdk:"id"`
378+
IPAddressType fwtypes.StringEnum[awstypes.ResourceGatewayIpAddressType] `tfsdk:"ip_address_type"`
379+
IPV4AddressesPerEni types.Int32 `tfsdk:"ipv4_addresses_per_eni"`
380+
Name types.String `tfsdk:"name"`
381+
SecurityGroupIDs fwtypes.SetOfString `tfsdk:"security_group_ids"`
382+
Status fwtypes.StringEnum[awstypes.ResourceGatewayStatus] `tfsdk:"status"`
383+
SubnetIDs fwtypes.SetOfString `tfsdk:"subnet_ids"`
384+
Tags tftags.Map `tfsdk:"tags"`
385+
TagsAll tftags.Map `tfsdk:"tags_all"`
386+
Timeouts timeouts.Value `tfsdk:"timeouts"`
387+
VPCID types.String `tfsdk:"vpc_id"`
368388
}

internal/service/vpclattice/resource_gateway_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,43 @@ func TestAccVPCLatticeResourceGateway_multipleSubnets(t *testing.T) {
165165
})
166166
}
167167

168+
func TestAccVPCLatticeResourceGateway_ipv4AddressesPerEni(t *testing.T) {
169+
ctx := acctest.Context(t)
170+
var resourcegateway vpclattice.GetResourceGatewayOutput
171+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
172+
resourceName := "aws_vpclattice_resource_gateway.test"
173+
addressType := "IPV4"
174+
175+
resource.ParallelTest(t, resource.TestCase{
176+
PreCheck: func() {
177+
acctest.PreCheck(ctx, t)
178+
acctest.PreCheckPartitionHasService(t, names.VPCLatticeEndpointID)
179+
},
180+
ErrorCheck: acctest.ErrorCheck(t, names.VPCLatticeServiceID),
181+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
182+
CheckDestroy: testAccCheckResourceGatewayDestroy(ctx),
183+
Steps: []resource.TestStep{
184+
{
185+
Config: testAccResourceGatewayConfig_ipv4AddressesPerEni(rName, 5),
186+
Check: resource.ComposeTestCheckFunc(
187+
testAccCheckResourceGatewayExists(ctx, resourceName, &resourcegateway),
188+
resource.TestCheckResourceAttr(resourceName, names.AttrIPAddressType, addressType),
189+
resource.TestCheckResourceAttr(resourceName, names.AttrStatus, "ACTIVE"),
190+
resource.TestCheckResourceAttr(resourceName, "security_group_ids.#", "1"),
191+
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
192+
resource.TestCheckResourceAttr(resourceName, "ipv4_addresses_per_eni", "5"),
193+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "vpc-lattice", regexache.MustCompile(`resourcegateway/rgw-.+`)),
194+
),
195+
},
196+
{
197+
ResourceName: resourceName,
198+
ImportState: true,
199+
ImportStateVerify: true,
200+
},
201+
},
202+
})
203+
}
204+
168205
func TestAccVPCLatticeResourceGateway_update(t *testing.T) {
169206
ctx := acctest.Context(t)
170207
var resourcegateway vpclattice.GetResourceGatewayOutput
@@ -385,6 +422,18 @@ resource "aws_vpclattice_resource_gateway" "test" {
385422
`, rName))
386423
}
387424

425+
func testAccResourceGatewayConfig_ipv4AddressesPerEni(rName string, ipAddressesPerEni int32) string {
426+
return acctest.ConfigCompose(testAccResourceGatewayConfig_base(rName), fmt.Sprintf(`
427+
resource "aws_vpclattice_resource_gateway" "test" {
428+
name = %[1]q
429+
vpc_id = aws_vpc.test.id
430+
security_group_ids = [aws_security_group.test.id]
431+
subnet_ids = [aws_subnet.test.id]
432+
ipv4_addresses_per_eni = %[2]d
433+
}
434+
`, rName, ipAddressesPerEni))
435+
}
436+
388437
func testAccResourceGatewayConfig_update1(rName string) string {
389438
return acctest.ConfigCompose(testAccResourceGatewayConfig_base(rName), fmt.Sprintf(`
390439
resource "aws_security_group" "test2" {

website/docs/r/vpclattice_resource_gateway.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The following arguments are optional:
6363

6464
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
6565
* `ip_address_type` - (Optional) IP address type used by the resource gateway. Valid values are `IPV4`, `IPV6`, and `DUALSTACK`. The IP address type of a resource gateway must be compatible with the subnets of the resource gateway and the IP address type of the resource.
66+
* `ipv4_addresses_per_eni` - (Optional) The number of IPv4 addresses per ENI for your resource. This argument is only applicable to `IPV4` and `DUALSTACK` IP address types. Defaults to `16`.
6667
* `security_group_ids` - (Optional) Security group IDs associated with the resource gateway. The security groups must be in the same VPC.
6768
* `tags` - (Optional) Key-value mapping of resource tags. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
6869

0 commit comments

Comments
 (0)