@ -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 ]
@ -68,7 +83,7 @@ func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc {
}
if attr [ "associations.0.subnet_id" ] != subnetRs . Primary . Attributes [ "id" ] {
return fmt . Errorf (
"subnet_id is %v; want %s",
"subnet_id is %v; want %s",
attr [ "associations.0.subnet_id" ] ,
subnetRs . Primary . Attributes [ "id" ] ,
)
@ -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" ]
}
}
`