Skip to content

Commit

Permalink
Merge pull request #648 from yahyapo/master
Browse files Browse the repository at this point in the history
Adding tag support to AWS EC2 route table resource.
  • Loading branch information
armon committed Dec 11, 2014
2 parents 9e6ce4b b595c73 commit 7a3b4fa
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
11 changes: 11 additions & 0 deletions builtin/providers/aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,8 @@ func resourceAwsRouteTable() *schema.Resource {
ForceNew: true,
},

"tags": tagsSchema(),

"route": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -129,6 131,9 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("route", route)

// Tags
d.Set("tags", tagsToMap(rt.Tags))

return nil
}

Expand Down Expand Up @@ -178,6 183,12 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
}
}

if err := setTags(ec2conn, d); err != nil {
return err
} else {
d.SetPartial("tags")
}

return resourceAwsRouteTableRead(d, meta)
}

Expand Down
57 changes: 57 additions & 0 deletions builtin/providers/aws/resource_aws_route_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 121,35 @@ func TestAccAWSRouteTable_instance(t *testing.T) {
})
}

func TestAccAWSRouteTable_tags(t *testing.T) {
var route_table ec2.RouteTable

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRouteTableDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRouteTableConfigTags,
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
testAccCheckTags(&route_table.Tags, "foo", "bar"),
),
},

resource.TestStep{
Config: testAccRouteTableConfigTagsUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
testAccCheckTags(&route_table.Tags, "foo", ""),
testAccCheckTags(&route_table.Tags, "bar", "baz"),
),
},
},
})
}


func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

Expand Down Expand Up @@ -249,3 278,31 @@ resource "aws_route_table" "foo" {
}
}
`

const testAccRouteTableConfigTags = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_route_table" "foo" {
vpc_id = "${aws_vpc.foo.id}"
tags {
foo = "bar"
}
}
`

const testAccRouteTableConfigTagsUpdate = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_route_table" "foo" {
vpc_id = "${aws_vpc.foo.id}"
tags {
bar = "baz"
}
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ description: |-

Provides a resource to create a VPC routing table.

## Example Usage
## Example usage with tags:

```
resource "aws_route_table" "r" {
Expand All @@ -19,6 19,10 @@ resource "aws_route_table" "r" {
cidr_block = "10.0.1.0/24"
gateway_id = "${aws_internet_gateway.main.id}"
}
tags {
Name = "main"
}
}
```

Expand All @@ -28,6 32,7 @@ The following arguments are supported:

* `vpc_id` - (Required) The ID of the routing table.
* `route` - (Optional) A list of route objects. Their keys are documented below.
* `tags` - (Optional) A mapping of tags to assign to the resource.

Each route supports the following:

Expand Down

0 comments on commit 7a3b4fa

Please sign in to comment.