Skip to content

Commit

Permalink
Add tests for group/child resource configurations and adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
drewtul committed Jan 21, 2025
1 parent 0790b4f commit 8d73f4d
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 8 deletions.
16 changes: 9 additions & 7 deletions internal/service/vpclattice/resource_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,25 @@ func (r *resourceResourceConfiguration) Schema(ctx context.Context, req resource
CustomType: fwtypes.StringEnumType[awstypes.ProtocolType](),
Optional: true,
Computed: true,
Default: stringdefault.StaticString(string(awstypes.ProtocolTypeTcp)),
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.RequiresReplaceIfConfigured(),
},
},
"resource_configuration_group_id": schema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{stringvalidator.ConflictsWith(
path.MatchRelative().AtParent().AtName("resource_gateway_identifier"),
)},
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName("resource_gateway_identifier")),
stringvalidator.ExactlyOneOf(path.MatchRelative().AtParent().AtName(names.AttrProtocol)),
},
},
"resource_gateway_identifier": schema.StringAttribute{
Required: true,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.RequiresReplaceIfConfigured(),
},
},
names.AttrTags: tftags.TagsAttribute(),
Expand Down Expand Up @@ -219,6 +220,7 @@ func (r *resourceResourceConfiguration) Create(ctx context.Context, req resource
return
}

input.ResourceConfigurationGroupIdentifier = plan.ResourceConfigurationGroupId.ValueStringPointer()
input.Tags = getTagsIn(ctx)

out, err := conn.CreateResourceConfiguration(ctx, &input)
Expand Down
82 changes: 81 additions & 1 deletion internal/service/vpclattice/resource_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/vpclattice/types"
"testing"

"github.com/YakDriver/regexache"
Expand Down Expand Up @@ -188,6 +189,51 @@ func TestAccVPCLatticeResourceConfiguration_ipAddress(t *testing.T) {
})
}

func TestAccVPCLatticeResourceConfiguration_parentChild(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var resourceconfiguration vpclattice.GetResourceConfigurationOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_vpclattice_resource_configuration.test"
resourceGatewayName := "aws_vpclattice_resource_gateway.test"
resourceParentName := "aws_vpclattice_resource_configuration.parent"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.VPCLatticeEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.VPCLatticeServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckResourceConfigurationDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccResourceConfigurationConfig_parentChild(rName, "10.0.0.1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckResourceConfigurationExists(ctx, resourceName, &resourceconfiguration),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, "resource_gateway_identifier", resourceGatewayName, names.AttrID),
resource.TestCheckResourceAttrPair(resourceName, "resource_configuration_group_id", resourceParentName, names.AttrID),
resource.TestCheckResourceAttr(resourceName, names.AttrType, string(types.ResourceConfigurationTypeChild)),
resource.TestCheckResourceAttr(resourceParentName, names.AttrType, string(types.ResourceConfigurationTypeGroup)),
resource.TestCheckResourceAttr(resourceName, "port_ranges.0", "80"),
resource.TestCheckResourceAttr(resourceName, "resource_configuration_definition.0.ip_resource.0.ip_address", "10.0.0.1"),
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "vpc-lattice", regexache.MustCompile(`resourceconfiguration/+.`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccVPCLatticeResourceConfiguration_disappears(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -287,6 +333,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id
port_ranges = ["80"]
protocol = "TCP"
resource_configuration_definition {
dns_resource {
Expand All @@ -308,6 +355,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id
port_ranges = ["80", "8080"]
protocol = "TCP"
resource_configuration_definition {
dns_resource {
Expand All @@ -329,10 +377,42 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id
port_ranges = ["80"]
protocol = "TCP"
resource_configuration_definition {
ip_resource {
ip_address = %[2]q
}
}
}
`, rName, ip))
}

func testAccResourceConfigurationConfig_parentChild(rName, ip string) string {
return acctest.ConfigCompose(testAccResourceGatewayConfig_basic(rName),
fmt.Sprintf(`
resource "aws_vpclattice_resource_configuration" "parent" {
name = "%[1]s-parent"
protocol = "TCP"
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id
type = "GROUP"
}
resource "aws_vpclattice_resource_configuration" "test" {
name = %[1]q
port_ranges = ["80"]
resource_configuration_group_id = aws_vpclattice_resource_configuration.parent.id
type = "CHILD"
resource_configuration_definition {
ip_resource {
ip_address= %[2]q
ip_address = %[2]q
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resource "aws_vpclattice_resource_configuration" "test" {
resource_gateway_identifier = aws_vpclattice_resource_gateway.test.id

port_ranges = ["80"]
protocol = "TCP"

resource_configuration_definition {
dns_resource {
Expand Down

0 comments on commit 8d73f4d

Please sign in to comment.