provider/aws: Fix panic on nil route configs

When creating an `aws_route_table`, if a `route` configuration block is left `nil`, Terraform would previously panic. This allows Terraform to catch a faulty interface conversion during the resource create. The resource will still fail to apply, however, since every item in the `route` element is `Optional` we cannot currently catch this error during plan time, via validation.

Fixes: #13545
This commit is contained in:
Jake Champlin 2017-04-11 14:45:10 -04:00
parent 49927ff106
commit db7fe7fe77
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
2 changed files with 33 additions and 1 deletions

View File

@ -452,7 +452,10 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
func resourceAwsRouteTableHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
m, castOk := v.(map[string]interface{})
if !castOk {
return 0
}
if v, ok := m["ipv6_cidr_block"]; ok {
buf.WriteString(fmt.Sprintf("%s-", v.(string)))

View File

@ -2,6 +2,7 @@ package aws
import (
"fmt"
"regexp"
"testing"
"github.com/aws/aws-sdk-go/aws"
@ -183,6 +184,21 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
})
}
func TestAccAWSRouteTable_panic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_route_table.foo",
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccRouteTableConfigPanic,
ExpectError: regexp.MustCompile("The request must contain the parameter destinationCidrBlock or destinationIpv6CidrBlock"),
},
},
})
}
func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
@ -497,3 +513,16 @@ resource "aws_route_table" "foo" {
propagating_vgws = ["${aws_vpn_gateway.foo.id}"]
}
`
const testAccRouteTableConfigPanic = `
resource "aws_vpc" "foo" {
cidr_block = "10.2.0.0/16"
}
resource "aws_route_table" "foo" {
vpc_id = "${aws_vpc.foo.id}"
route {
}
}
`