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

fix: fix aws_vpclattice_service_network_vpc_association forced replacement #32658

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -61,6 +62,13 @@ func ResourceServiceNetworkVPCAssociation() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// Users can provide both IDs or ARNs, while the API returns the ID
old_id := old[strings.LastIndex(old, "/")+1:]
new_id := new[strings.LastIndex(new, "/")+1:]

return old_id == new_id
},
},
"status": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ func TestAccVPCLatticeServiceNetworkVPCAssociation_basic(t *testing.T) {
})
}

func TestAccVPCLatticeServiceNetworkVPCAssociation_arn(t *testing.T) {
ctx := acctest.Context(t)

var servicenetworkvpcasc vpclattice.GetServiceNetworkVpcAssociationOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_vpclattice_service_network_vpc_association.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.VPCLatticeEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.VPCLatticeEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckServiceNetworkVPCAssociationDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccServiceNetworkVPCAssociationConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceNetworkVPCAssociationExists(ctx, resourceName, &servicenetworkvpcasc),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "vpc-lattice", regexp.MustCompile("servicenetworkvpcassociation/.+$")),
resource.TestCheckResourceAttrSet(resourceName, "service_network_identifier"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccVPCLatticeServiceNetworkVPCAssociation_disappears(t *testing.T) {
ctx := acctest.Context(t)

Expand Down Expand Up @@ -238,6 +272,23 @@ resource "aws_vpclattice_service_network_vpc_association" "test" {
`, rName)
}

func testAccServiceNetworkVPCAssociationConfig_arn(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
}

resource "aws_vpclattice_service_network" "test" {
name = %[1]q
}

resource "aws_vpclattice_service_network_vpc_association" "test" {
vpc_identifier = aws_vpc.test.id
service_network_identifier = aws_vpclattice_service_network.test.arn
}
`, rName)
}

func testAccServiceNetworkVPCAssociationConfig_full(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
Expand Down