Merge pull request #11152 from hashicorp/b-aws-route-table-11134
provider/aws: Fix panic caused by main route table lookup
This commit is contained in:
commit
3de923d13f
|
@ -197,7 +197,10 @@ func dataSourceAssociationsRead(ec2Assocations []*ec2.RouteTableAssociation) []m
|
|||
m := make(map[string]interface{})
|
||||
m["route_table_id"] = *a.RouteTableId
|
||||
m["route_table_association_id"] = *a.RouteTableAssociationId
|
||||
// GH[11134]
|
||||
if a.SubnetId != nil {
|
||||
m["subnet_id"] = *a.SubnetId
|
||||
}
|
||||
m["main"] = *a.Main
|
||||
associations = append(associations, m)
|
||||
}
|
||||
|
|
|
@ -25,6 +25,21 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDataSourceAwsRouteTable_main(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccDataSourceAwsRouteTableMainRoute,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccDataSourceAwsRouteTableCheckMain("data.aws_route_table.by_filter"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
|
@ -78,6 +93,32 @@ func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func testAccDataSourceAwsRouteTableCheckMain(name string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[name]
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("root module has no resource called %s", name)
|
||||
}
|
||||
|
||||
attr := rs.Primary.Attributes
|
||||
|
||||
// Verify attributes are set
|
||||
if _, ok := attr["id"]; !ok {
|
||||
return fmt.Errorf("id not set for main route table")
|
||||
}
|
||||
if _, ok := attr["vpc_id"]; !ok {
|
||||
return fmt.Errorf("vpc_id not set for main route table")
|
||||
}
|
||||
// Verify it's actually the main route table that's returned
|
||||
if attr["associations.0.main"] != "true" {
|
||||
return fmt.Errorf("main route table not found")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
const testAccDataSourceAwsRouteTableGroupConfig = `
|
||||
provider "aws" {
|
||||
region = "eu-central-1"
|
||||
|
@ -130,3 +171,17 @@ data "aws_route_table" "by_subnet" {
|
|||
}
|
||||
|
||||
`
|
||||
|
||||
// Uses us-east-2, as region only has a single main route table
|
||||
const testAccDataSourceAwsRouteTableMainRoute = `
|
||||
provider "aws" {
|
||||
region = "us-east-2"
|
||||
}
|
||||
|
||||
data "aws_route_table" "by_filter" {
|
||||
filter {
|
||||
name = "association.main"
|
||||
values = ["true"]
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue