Merge pull request #11157 from hashicorp/b-add-id-route-table

provider/aws: Add missing id argument for Route Table data source
pull/11158/head
Jake Champlin 9 years ago committed by GitHub
commit ed275af697

@ -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),
},

@ -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

@ -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.

Loading…
Cancel
Save