Skip to content

Commit d8526be

Browse files
Add ipv4_addresses_per_eni argument to aws_vpclattice_resource_gateway
1 parent 27fd727 commit d8526be

File tree

2 files changed

+80
-11
lines changed

2 files changed

+80
-11
lines changed

internal/service/vpclattice/resource_gateway.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ 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/int32default"
21+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
1922
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
2023
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
2124
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -67,6 +70,17 @@ func (r *resourceGatewayResource) Schema(ctx context.Context, request resource.S
6770
stringplanmodifier.UseStateForUnknown(),
6871
},
6972
},
73+
"ipv4_addresses_per_eni": schema.Int32Attribute{
74+
Optional: true,
75+
Validators: []validator.Int32{
76+
int32validator.AtLeast(1),
77+
int32validator.AtMost(62),
78+
},
79+
PlanModifiers: []planmodifier.Int32{
80+
int32planmodifier.RequiresReplace(),
81+
},
82+
Default: int32default.StaticInt32(16),
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]q
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" {

0 commit comments

Comments
 (0)