diff --git a/builtin/providers/aws/data_source_aws_route_table.go b/builtin/providers/aws/data_source_aws_route_table.go index d8399df9ed16..6f6667262e6e 100644 --- a/builtin/providers/aws/data_source_aws_route_table.go +++ b/builtin/providers/aws/data_source_aws_route_table.go @@ -4,6 +4,7 @@ import ( "fmt" "log" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform/helper/schema" ) @@ -138,7 +139,8 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error rt := resp.RouteTables[0] - d.SetId(*rt.RouteTableId) + d.SetId(aws.StringValue(rt.RouteTableId)) + d.Set("route_table_id", rt.RouteTableId) d.Set("vpc_id", rt.VpcId) d.Set("tags", tagsToMap(rt.Tags)) if err := d.Set("routes", dataSourceRoutesRead(rt.Routes)); err != nil { diff --git a/builtin/providers/aws/data_source_aws_route_table_test.go b/builtin/providers/aws/data_source_aws_route_table_test.go index 16b2e4ec9d6d..f459dd33bfe2 100644 --- a/builtin/providers/aws/data_source_aws_route_table_test.go +++ b/builtin/providers/aws/data_source_aws_route_table_test.go @@ -1,3 +1,4 @@ +// make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccDataSourceAwsRouteTable_' package aws import ( @@ -8,7 +9,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccDataSourceAwsRouteTable(t *testing.T) { +func TestAccDataSourceAwsRouteTable_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -21,6 +22,7 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) { testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_subnet"), testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_id"), ), + ExpectNonEmptyPlan: true, }, }, }) @@ -71,6 +73,14 @@ func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc { ) } + if attr["route_table_id"] != rts.Primary.Attributes["id"] { + return fmt.Errorf( + "route_table_id is %s; want %s", + attr["route_table_id"], + rts.Primary.Attributes["id"], + ) + } + if attr["vpc_id"] != vpcRs.Primary.Attributes["id"] { return fmt.Errorf( "vpc_id is %s; want %s", @@ -184,6 +194,14 @@ provider "aws" { region = "us-east-2" } +resource "aws_vpc" "test" { + cidr_block = "172.16.0.0/16" + + tags { + Name = "terraform-testacc-data-source" + } +} + data "aws_route_table" "by_filter" { filter { name = "association.main" @@ -191,7 +209,7 @@ data "aws_route_table" "by_filter" { } filter { name = "vpc-id" - values = ["vpc-6bd70802"] + values = ["${aws_vpc.test.id}"] } } `