diff --git a/builtin/providers/aws/data_source_aws_route_table.go b/builtin/providers/aws/data_source_aws_route_table.go index c09d7ce8fb..d8399df9ed 100644 --- a/builtin/providers/aws/data_source_aws_route_table.go +++ b/builtin/providers/aws/data_source_aws_route_table.go @@ -18,6 +18,11 @@ func dataSourceAwsRouteTable() *schema.Resource { Optional: true, Computed: true, }, + "route_table_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, "vpc_id": { Type: schema.TypeString, Optional: true, @@ -98,14 +103,16 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error req := &ec2.DescribeRouteTablesInput{} vpcId, vpcIdOk := d.GetOk("vpc_id") subnetId, subnetIdOk := d.GetOk("subnet_id") + rtbId, rtbOk := d.GetOk("route_table_id") tags, tagsOk := d.GetOk("tags") filter, filterOk := d.GetOk("filter") - if !vpcIdOk && !subnetIdOk && !tagsOk && !filterOk { - return fmt.Errorf("One of vpc_id, subnet_id, filters, or tags must be assigned") + if !vpcIdOk && !subnetIdOk && !tagsOk && !filterOk && !rtbOk { + return fmt.Errorf("One of route_table_id, vpc_id, subnet_id, filters, or tags must be assigned") } req.Filters = buildEC2AttributeFilterList( map[string]string{ + "route-table-id": rtbId.(string), "vpc-id": vpcId.(string), "association.subnet-id": subnetId.(string), }, 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 9a5696b669..b4f6305f61 100644 --- a/builtin/providers/aws/data_source_aws_route_table_test.go +++ b/builtin/providers/aws/data_source_aws_route_table_test.go @@ -19,6 +19,7 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) { testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_tag"), testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_filter"), testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_subnet"), + testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_id"), ), }, }, @@ -165,11 +166,16 @@ data "aws_route_table" "by_tag" { } depends_on = ["aws_route_table_association.a"] } + data "aws_route_table" "by_subnet" { subnet_id = "${aws_subnet.test.id}" depends_on = ["aws_route_table_association.a"] } +data "aws_route_table" "by_id" { + route_table_id = "${aws_route_table.test.id}" + depends_on = ["aws_route_table_association.a"] +} ` // Uses us-east-2, as region only has a single main route table diff --git a/website/source/docs/providers/aws/d/route_table.html.markdown b/website/source/docs/providers/aws/d/route_table.html.markdown index 9b11d8d1de..4da99d1c07 100644 --- a/website/source/docs/providers/aws/d/route_table.html.markdown +++ b/website/source/docs/providers/aws/d/route_table.html.markdown @@ -42,7 +42,7 @@ Route Table whose data will be exported as attributes. * `filter` - (Optional) Custom filter block as described below. -* `id` - (Optional) The id of the specific Route Table to retrieve. +* `route_table_id` - (Optional) The id of the specific Route Table to retrieve. * `tags` - (Optional) A mapping of tags, each pair of which must exactly match a pair on the desired Route Table.