Merge pull request #648 from yahyapo/master

Adding tag support to AWS EC2 route table resource.
This commit is contained in:
Armon Dadgar 2014-12-10 19:24:38 -08:00
commit 7a3b4fa7ce
3 changed files with 74 additions and 1 deletions

View File

@ -26,6 +26,8 @@ func resourceAwsRouteTable() *schema.Resource {
ForceNew: true,
},
"tags": tagsSchema(),
"route": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
@ -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
}
@ -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)
}

View File

@ -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
@ -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"
}
}
`

View File

@ -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" {
@ -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"
}
}
```
@ -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: