From d794bdfc2644f1815265309c804259eb067adbeb Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 11 Jan 2017 13:16:52 -0500 Subject: [PATCH 1/3] 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`. --- builtin/providers/aws/data_source_aws_route_table.go | 11 +++++++++-- .../providers/aws/data_source_aws_route_table_test.go | 6 ++++++ .../docs/providers/aws/d/route_table.html.markdown | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_route_table.go b/builtin/providers/aws/data_source_aws_route_table.go index c09d7ce8fb..09f70e9d1b 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, }, + "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), }, 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..7114c8d183 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" { + 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 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..b27175ff74 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. +* `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. From 439b94707e60035db90dc0773d281a26c3e147cf Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 11 Jan 2017 13:22:29 -0500 Subject: [PATCH 2/3] Use 'route_table_id' instead of 'rtb_id' --- builtin/providers/aws/data_source_aws_route_table.go | 4 ++-- builtin/providers/aws/data_source_aws_route_table_test.go | 2 +- website/source/docs/providers/aws/d/route_table.html.markdown | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/data_source_aws_route_table.go b/builtin/providers/aws/data_source_aws_route_table.go index 09f70e9d1b..bdbcda5165 100644 --- a/builtin/providers/aws/data_source_aws_route_table.go +++ b/builtin/providers/aws/data_source_aws_route_table.go @@ -18,7 +18,7 @@ func dataSourceAwsRouteTable() *schema.Resource { Optional: true, Computed: true, }, - "rtb_id": { + "route_table_id": { Type: schema.TypeString, Optional: true, Computed: true, @@ -103,7 +103,7 @@ 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") + rtbId, rtbOk := d.GetOk("route_table_id") tags, tagsOk := d.GetOk("tags") filter, filterOk := d.GetOk("filter") 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 7114c8d183..b4f6305f61 100644 --- a/builtin/providers/aws/data_source_aws_route_table_test.go +++ b/builtin/providers/aws/data_source_aws_route_table_test.go @@ -173,7 +173,7 @@ data "aws_route_table" "by_subnet" { } data "aws_route_table" "by_id" { - rtb_id = "${aws_route_table.test.id}" + route_table_id = "${aws_route_table.test.id}" depends_on = ["aws_route_table_association.a"] } ` 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 b27175ff74..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. -* `rtb_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. From 642e0107e12b4ebbefec73effe0fab617525a600 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 11 Jan 2017 13:23:40 -0500 Subject: [PATCH 3/3] Update error message to 'route_table_id' --- builtin/providers/aws/data_source_aws_route_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/data_source_aws_route_table.go b/builtin/providers/aws/data_source_aws_route_table.go index bdbcda5165..d8399df9ed 100644 --- a/builtin/providers/aws/data_source_aws_route_table.go +++ b/builtin/providers/aws/data_source_aws_route_table.go @@ -108,7 +108,7 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error filter, filterOk := d.GetOk("filter") if !vpcIdOk && !subnetIdOk && !tagsOk && !filterOk && !rtbOk { - return fmt.Errorf("One of rtb_id, vpc_id, subnet_id, filters, or tags must be assigned") + return fmt.Errorf("One of route_table_id, vpc_id, subnet_id, filters, or tags must be assigned") } req.Filters = buildEC2AttributeFilterList( map[string]string{