Skip to content

Commit

Permalink
Merge pull request #11157 from hashicorp/b-add-id-route-table
Browse files Browse the repository at this point in the history
provider/aws: Add missing id argument for Route Table data source
  • Loading branch information
grubernaut authored Jan 11, 2017
2 parents ec7fdab + 642e010 commit ed275af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions builtin/providers/aws/data_source_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
},
Expand Down
6 changes: 6 additions & 0 deletions builtin/providers/aws/data_source_aws_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ed275af

Please sign in to comment.