Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tag support to AWS EC2 route table resource. #648

Merged
merged 1 commit into from
Dec 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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