Skip to content

Commit

Permalink
Merge pull request #29994 from cmccabe-ws/b-aws_route_vpc_endpoint_ta…
Browse files Browse the repository at this point in the history
…rget_ipv6_destinations

🐛 AWS Route now Support IPv6 Destinations with VPC Endpoints as Targets
  • Loading branch information
ewbankkit authored Mar 14, 2023
2 parents 1a2915f + aa8033d commit 32b5b87
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/29994.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_route: Allow `destination_ipv6_cidr_block` to be specified for a `vpc_endpoint_id` target
```
3 changes: 1 addition & 2 deletions internal/service/ec2/vpc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ func ResourceRoute() *schema.Resource {
Optional: true,
ExactlyOneOf: routeValidTargets,
ConflictsWith: []string{
routeDestinationIPv6CIDRBlock, // IPv4 destinations only.
routeDestinationPrefixListID, // "Cannot create or replace a prefix list route targeting a VPC Endpoint."
routeDestinationPrefixListID, // "Cannot create or replace a prefix list route targeting a VPC Endpoint."
},
},
"vpc_peering_connection_id": {
Expand Down
121 changes: 121 additions & 0 deletions internal/service/ec2/vpc_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,57 @@ func TestAccVPCRoute_ipv4ToVPCEndpoint(t *testing.T) {
})
}

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

var route ec2.Route
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_route.test"
vpcEndpointResourceName := "aws_vpc_endpoint.test"
destinationIpv6Cidr := "::/0"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheckELBv2GatewayLoadBalancer(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID, "elasticloadbalancing"),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckRouteDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccVPCRouteConfig_resourceIPv6Endpoint(rName, destinationIpv6Cidr),
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteExists(ctx, resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "core_network_arn", ""),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationIpv6Cidr),
resource.TestCheckResourceAttr(resourceName, "destination_prefix_list_id", ""),
resource.TestCheckResourceAttr(resourceName, "egress_only_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "instance_id", ""),
resource.TestCheckResourceAttr(resourceName, "instance_owner_id", ""),
resource.TestCheckResourceAttr(resourceName, "local_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "nat_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "network_interface_id", ""),
resource.TestCheckResourceAttr(resourceName, "origin", ec2.RouteOriginCreateRoute),
resource.TestCheckResourceAttr(resourceName, "state", ec2.RouteStateActive),
resource.TestCheckResourceAttr(resourceName, "transit_gateway_id", ""),
resource.TestCheckResourceAttrPair(resourceName, "vpc_endpoint_id", vpcEndpointResourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccRouteImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

// https://github.com/hashicorp/terraform-provider-aws/issues/11455.
func TestAccVPCRoute_localRoute(t *testing.T) {
ctx := acctest.Context(t)
Expand Down Expand Up @@ -3312,6 +3363,76 @@ resource "aws_route" "test" {
`, rName, destinationCidr))
}

func testAccVPCRouteConfig_resourceIPv6Endpoint(rName, destinationIpv6Cidr string) string {
return acctest.ConfigCompose(
acctest.ConfigAvailableAZsNoOptIn(),
fmt.Sprintf(`
data "aws_caller_identity" "current" {}
resource "aws_vpc" "test" {
cidr_block = "10.10.10.0/25"
tags = {
Name = %[1]q
}
}
resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 2, 0)
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
}
}
resource "aws_lb" "test" {
load_balancer_type = "gateway"
name = %[1]q
subnet_mapping {
subnet_id = aws_subnet.test.id
}
}
resource "aws_vpc_endpoint_service" "test" {
acceptance_required = false
allowed_principals = [data.aws_caller_identity.current.arn]
gateway_load_balancer_arns = [aws_lb.test.arn]
tags = {
Name = %[1]q
}
}
resource "aws_vpc_endpoint" "test" {
service_name = aws_vpc_endpoint_service.test.service_name
subnet_ids = [aws_subnet.test.id]
vpc_endpoint_type = aws_vpc_endpoint_service.test.service_type
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
}
}
resource "aws_route_table" "test" {
vpc_id = aws_vpc.test.id
tags = {
Name = %[1]q
}
}
resource "aws_route" "test" {
route_table_id = aws_route_table.test.id
destination_ipv6_cidr_block = %[2]q
vpc_endpoint_id = aws_vpc_endpoint.test.id
}
`, rName, destinationIpv6Cidr))
}

func testAccVPCRouteConfig_ipv4FlexiTarget(rName, destinationCidr, targetAttribute, targetValue string) string {
return acctest.ConfigCompose(
acctest.ConfigLatestAmazonLinuxHVMEBSAMI(),
Expand Down

0 comments on commit 32b5b87

Please sign in to comment.