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

r/aws_route: NAT Gateway targets support IPv6 destinations #23427

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/23427.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_route: `nat_gateway_id` target no longer conflicts with `destination_ipv6_cidr_block`
```
7 changes: 3 additions & 4 deletions internal/service/ec2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ func ResourceRoute() *schema.Resource {
ExactlyOneOf: routeValidTargets,
},
"nat_gateway_id": {
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: routeValidTargets,
ConflictsWith: []string{"destination_ipv6_cidr_block"}, // IPv4 destinations only.
Type: schema.TypeString,
Optional: true,
ExactlyOneOf: routeValidTargets,
},
"network_interface_id": {
Type: schema.TypeString,
Expand Down
94 changes: 94 additions & 0 deletions internal/service/ec2/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,51 @@ func TestAccEC2Route_ipv4ToNatGateway(t *testing.T) {
})
}

func TestAccEC2Route_ipv6ToNatGateway(t *testing.T) {
var route ec2.Route
resourceName := "aws_route.test"
ngwResourceName := "aws_nat_gateway.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
destinationCidr := "64:ff9b::/96"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccRouteIPv6NatGatewayConfig(rName, destinationCidr),
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteExists(resourceName, &route),
resource.TestCheckResourceAttr(resourceName, "carrier_gateway_id", ""),
resource.TestCheckResourceAttr(resourceName, "destination_cidr_block", ""),
resource.TestCheckResourceAttr(resourceName, "destination_ipv6_cidr_block", destinationCidr),
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.TestCheckResourceAttrPair(resourceName, "nat_gateway_id", ngwResourceName, "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.TestCheckResourceAttr(resourceName, "vpc_endpoint_id", ""),
resource.TestCheckResourceAttr(resourceName, "vpc_peering_connection_id", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateIdFunc: testAccRouteImportStateIdFunc(resourceName),
ImportStateVerify: true,
},
},
})
}

func TestAccEC2Route_doesNotCrashWithVPCEndpoint(t *testing.T) {
var route ec2.Route
var routeTable ec2.RouteTable
Expand Down Expand Up @@ -2990,6 +3035,55 @@ resource "aws_route" "test" {
`, rName, destinationCidr)
}

func testAccRouteIPv6NatGatewayConfig(rName, destinationCidr string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.1.0.0/16"
assign_generated_ipv6_cidr_block = true

tags = {
Name = %[1]q
}
}

resource "aws_subnet" "test" {
vpc_id = aws_vpc.test.id
cidr_block = "10.1.1.0/24"
ipv6_cidr_block = cidrsubnet(aws_vpc.test.ipv6_cidr_block, 8, 1)
assign_ipv6_address_on_creation = true

enable_resource_name_dns_aaaa_record_on_launch = true

tags = {
Name = %[1]q
}
}

resource "aws_nat_gateway" "test" {
connectivity_type = "private"
subnet_id = aws_subnet.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
nat_gateway_id = aws_nat_gateway.test.id
}
`, rName, destinationCidr)
}

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