Skip to content

Commit ed275af

Browse files
authored
Merge pull request hashicorp#11157 from hashicorp/b-add-id-route-table
provider/aws: Add missing id argument for Route Table data source
2 parents ec7fdab + 642e010 commit ed275af

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

builtin/providers/aws/data_source_aws_route_table.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func dataSourceAwsRouteTable() *schema.Resource {
1818
Optional: true,
1919
Computed: true,
2020
},
21+
"route_table_id": {
22+
Type: schema.TypeString,
23+
Optional: true,
24+
Computed: true,
25+
},
2126
"vpc_id": {
2227
Type: schema.TypeString,
2328
Optional: true,
@@ -98,14 +103,16 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error
98103
req := &ec2.DescribeRouteTablesInput{}
99104
vpcId, vpcIdOk := d.GetOk("vpc_id")
100105
subnetId, subnetIdOk := d.GetOk("subnet_id")
106+
rtbId, rtbOk := d.GetOk("route_table_id")
101107
tags, tagsOk := d.GetOk("tags")
102108
filter, filterOk := d.GetOk("filter")
103109

104-
if !vpcIdOk && !subnetIdOk && !tagsOk && !filterOk {
105-
return fmt.Errorf("One of vpc_id, subnet_id, filters, or tags must be assigned")
110+
if !vpcIdOk && !subnetIdOk && !tagsOk && !filterOk && !rtbOk {
111+
return fmt.Errorf("One of route_table_id, vpc_id, subnet_id, filters, or tags must be assigned")
106112
}
107113
req.Filters = buildEC2AttributeFilterList(
108114
map[string]string{
115+
"route-table-id": rtbId.(string),
109116
"vpc-id": vpcId.(string),
110117
"association.subnet-id": subnetId.(string),
111118
},

builtin/providers/aws/data_source_aws_route_table_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) {
1919
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_tag"),
2020
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_filter"),
2121
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_subnet"),
22+
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_id"),
2223
),
2324
},
2425
},
@@ -165,11 +166,16 @@ data "aws_route_table" "by_tag" {
165166
}
166167
depends_on = ["aws_route_table_association.a"]
167168
}
169+
168170
data "aws_route_table" "by_subnet" {
169171
subnet_id = "${aws_subnet.test.id}"
170172
depends_on = ["aws_route_table_association.a"]
171173
}
172174
175+
data "aws_route_table" "by_id" {
176+
route_table_id = "${aws_route_table.test.id}"
177+
depends_on = ["aws_route_table_association.a"]
178+
}
173179
`
174180

175181
// Uses us-east-2, as region only has a single main route table

website/source/docs/providers/aws/d/route_table.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Route Table whose data will be exported as attributes.
4242

4343
* `filter` - (Optional) Custom filter block as described below.
4444

45-
* `id` - (Optional) The id of the specific Route Table to retrieve.
45+
* `route_table_id` - (Optional) The id of the specific Route Table to retrieve.
4646

4747
* `tags` - (Optional) A mapping of tags, each pair of which must exactly match
4848
a pair on the desired Route Table.

0 commit comments

Comments
 (0)