Skip to content

Commit

Permalink
Return route_table_id from aws_route_table data source. (hashicorp#11703
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ewbankkit authored and arcadiatea committed Feb 7, 2017
1 parent 2cb14b3 commit ca12541
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion builtin/providers/aws/data_source_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -138,7 +139,8 @@ func dataSourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error

rt := resp.RouteTables[0]

d.SetId(*rt.RouteTableId)
d.SetId(aws.StringValue(rt.RouteTableId))
d.Set("route_table_id", rt.RouteTableId)
d.Set("vpc_id", rt.VpcId)
d.Set("tags", tagsToMap(rt.Tags))
if err := d.Set("routes", dataSourceRoutesRead(rt.Routes)); err != nil {
Expand Down
22 changes: 20 additions & 2 deletions builtin/providers/aws/data_source_aws_route_table_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccDataSourceAwsRouteTable_'
package aws

import (
Expand All @@ -8,7 +9,7 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestAccDataSourceAwsRouteTable(t *testing.T) {
func TestAccDataSourceAwsRouteTable_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -21,6 +22,7 @@ func TestAccDataSourceAwsRouteTable(t *testing.T) {
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_subnet"),
testAccDataSourceAwsRouteTableCheck("data.aws_route_table.by_id"),
),
ExpectNonEmptyPlan: true,
},
},
})
Expand Down Expand Up @@ -71,6 +73,14 @@ func testAccDataSourceAwsRouteTableCheck(name string) resource.TestCheckFunc {
)
}

if attr["route_table_id"] != rts.Primary.Attributes["id"] {
return fmt.Errorf(
"route_table_id is %s; want %s",
attr["route_table_id"],
rts.Primary.Attributes["id"],
)
}

if attr["vpc_id"] != vpcRs.Primary.Attributes["id"] {
return fmt.Errorf(
"vpc_id is %s; want %s",
Expand Down Expand Up @@ -184,14 +194,22 @@ provider "aws" {
region = "us-east-2"
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
tags {
Name = "terraform-testacc-data-source"
}
}
data "aws_route_table" "by_filter" {
filter {
name = "association.main"
values = ["true"]
}
filter {
name = "vpc-id"
values = ["vpc-6bd70802"]
values = ["${aws_vpc.test.id}"]
}
}
`

0 comments on commit ca12541

Please sign in to comment.