Merge pull request #13548 from hashicorp/b-fix-route-table-panic

provider/aws: Fix panic on nil route configs
This commit is contained in:
Jake Champlin 2017-04-12 09:25:05 -04:00 committed by GitHub
commit c5a87af219
2 changed files with 35 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,22 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
})
}
// For GH-13545, Fixes panic on an empty route config block
func TestAccAWSRouteTable_panicEmptyRoute(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: testAccRouteTableConfigPanicEmptyRoute,
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 +514,17 @@ resource "aws_route_table" "foo" {
propagating_vgws = ["${aws_vpn_gateway.foo.id}"]
}
`
// For GH-13545
const testAccRouteTableConfigPanicEmptyRoute = `
resource "aws_vpc" "foo" {
cidr_block = "10.2.0.0/16"
}
resource "aws_route_table" "foo" {
vpc_id = "${aws_vpc.foo.id}"
route {
}
}
`