provider/aws: Add missing id argument for Route Table data source

Documentation for the `aws_route_table` data source mentions that it supports a route table `id` as an argument, however it was missing from the actual provider code.

Adds in the missing provider code, adds a test, and updates the documentation to use `rtb_id` as the argument, instead of the more ambiguous `id`.
This commit is contained in:
Jake Champlin 2017-01-11 13:16:52 -05:00
parent ec7fdab16d
commit d794bdfc26
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
3 changed files with 16 additions and 3 deletions

View File

@ -18,6 +18,11 @@ func dataSourceAwsRouteTable() *schema.Resource {
Optional: true,
Computed: true,
},
"rtb_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("rtb_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 rtb_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),
},

View File

@ -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" {
rtb_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

View File

@ -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.
* `rtb_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.