provider/aws: Allow Internet Gateway IPv6 routes (#14484)

Fixes: #14006
Fixes: #14464

IPv6 wasn't supported for adding routes to the internet gateway.
Resulted in a message as follows:

```
Error creating route: MissingParameter: The request must contain the parameter destinationCidrBlock or destinationIpv6CidrBlock
```

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSRoute_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/05/15 11:50:43 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSRoute_ -timeout 120m
=== RUN   TestAccAWSRoute_basic
--- PASS: TestAccAWSRoute_basic (67.27s)
=== RUN   TestAccAWSRoute_ipv6Support
--- PASS: TestAccAWSRoute_ipv6Support (59.35s)
=== RUN   TestAccAWSRoute_ipv6ToInternetGateway
--- PASS: TestAccAWSRoute_ipv6ToInternetGateway (67.39s)
=== RUN   TestAccAWSRoute_changeCidr
--- PASS: TestAccAWSRoute_changeCidr (103.68s)
=== RUN   TestAccAWSRoute_noopdiff
--- PASS: TestAccAWSRoute_noopdiff (194.32s)
=== RUN   TestAccAWSRoute_doesNotCrashWithVPCEndpoint
--- PASS: TestAccAWSRoute_doesNotCrashWithVPCEndpoint (71.36s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	563.397s
```
This commit is contained in:
Paul Stack 2017-05-15 15:48:38 +03:00 committed by GitHub
parent ef4914e300
commit d5bb844684
2 changed files with 57 additions and 3 deletions

View File

@ -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)),

View File

@ -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"