diff --git a/builtin/providers/aws/resource_aws_route.go b/builtin/providers/aws/resource_aws_route.go index b33dfe3b7..4836d5123 100644 --- a/builtin/providers/aws/resource_aws_route.go +++ b/builtin/providers/aws/resource_aws_route.go @@ -133,10 +133,18 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error { switch setTarget { case "gateway_id": createOpts = &ec2.CreateRouteInput{ - RouteTableId: aws.String(d.Get("route_table_id").(string)), - DestinationCidrBlock: aws.String(d.Get("destination_cidr_block").(string)), - GatewayId: aws.String(d.Get("gateway_id").(string)), + RouteTableId: aws.String(d.Get("route_table_id").(string)), + GatewayId: aws.String(d.Get("gateway_id").(string)), } + + if v, ok := d.GetOk("destination_cidr_block"); ok { + createOpts.DestinationCidrBlock = aws.String(v.(string)) + } + + if v, ok := d.GetOk("destination_ipv6_cidr_block"); ok { + createOpts.DestinationIpv6CidrBlock = aws.String(v.(string)) + } + case "egress_only_gateway_id": createOpts = &ec2.CreateRouteInput{ RouteTableId: aws.String(d.Get("route_table_id").(string)), diff --git a/builtin/providers/aws/resource_aws_route_test.go b/builtin/providers/aws/resource_aws_route_test.go index a8bc00373..24459689b 100644 --- a/builtin/providers/aws/resource_aws_route_test.go +++ b/builtin/providers/aws/resource_aws_route_test.go @@ -86,6 +86,26 @@ func TestAccAWSRoute_ipv6Support(t *testing.T) { }) } +func TestAccAWSRoute_ipv6ToInternetGateway(t *testing.T) { + var route ec2.Route + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSRouteDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSRouteConfigIpv6InternetGateway, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSRouteExists("aws_route.igw", &route), + ), + }, + }, + }) +} + func TestAccAWSRoute_changeCidr(t *testing.T) { var route ec2.Route var routeTable ec2.RouteTable @@ -288,6 +308,32 @@ resource "aws_route" "bar" { } `) +var testAccAWSRouteConfigIpv6InternetGateway = fmt.Sprintf(` +resource "aws_vpc" "foo" { + cidr_block = "10.1.0.0/16" + assign_generated_ipv6_cidr_block = true +} + +resource "aws_egress_only_internet_gateway" "foo" { + vpc_id = "${aws_vpc.foo.id}" +} + +resource "aws_internet_gateway" "foo" { + vpc_id = "${aws_vpc.foo.id}" +} + +resource "aws_route_table" "external" { + vpc_id = "${aws_vpc.foo.id}" +} + +resource "aws_route" "igw" { + route_table_id = "${aws_route_table.external.id}" + destination_ipv6_cidr_block = "::/0" + gateway_id = "${aws_internet_gateway.foo.id}" +} + +`) + var testAccAWSRouteConfigIpv6 = fmt.Sprintf(` resource "aws_vpc" "foo" { cidr_block = "10.1.0.0/16"