From b595c73d421c77b39b63f2a53e41ef9527247878 Mon Sep 17 00:00:00 2001 From: Yahya Poonawala Date: Thu, 11 Dec 2014 00:03:13 +0530 Subject: [PATCH] Adding tag support to AWS EC2 route table resource. --- .../providers/aws/resource_aws_route_table.go | 11 ++++ .../aws/resource_aws_route_table_test.go | 57 +++++++++++++++++++ .../providers/aws/r/route_table.html.markdown | 7 ++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 841e456dd..0b681fd84 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -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) } diff --git a/builtin/providers/aws/resource_aws_route_table_test.go b/builtin/providers/aws/resource_aws_route_table_test.go index 45cae1fb8..0cc8b22f0 100644 --- a/builtin/providers/aws/resource_aws_route_table_test.go +++ b/builtin/providers/aws/resource_aws_route_table_test.go @@ -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" + } +} +` diff --git a/website/source/docs/providers/aws/r/route_table.html.markdown b/website/source/docs/providers/aws/r/route_table.html.markdown index 37a9d89ac..2080e192d 100644 --- a/website/source/docs/providers/aws/r/route_table.html.markdown +++ b/website/source/docs/providers/aws/r/route_table.html.markdown @@ -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: