diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go index af2c0f6d7..91eb7125c 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway.go +++ b/builtin/providers/aws/resource_aws_internet_gateway.go @@ -22,6 +22,7 @@ func resourceAwsInternetGateway() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "tags": tagsSchema(), }, } } @@ -66,6 +67,8 @@ func resourceAwsInternetGatewayRead(d *schema.ResourceData, meta interface{}) er d.Set("vpc_id", ig.Attachments[0].VpcId) } + d.Set("tags", tagsToMap(ig.Tags)) + return nil } @@ -82,6 +85,14 @@ func resourceAwsInternetGatewayUpdate(d *schema.ResourceData, meta interface{}) } } + ec2conn := meta.(*AWSClient).ec2conn + + if err := setTags(ec2conn, d); err != nil { + return err + } + + d.SetPartial("tags") + return nil } @@ -163,9 +174,9 @@ func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{}) ec2conn := meta.(*AWSClient).ec2conn // Get the old VPC ID to detach from - vpc_id, _ := d.GetChange("vpc_id") + vpcID, _ := d.GetChange("vpc_id") - if vpc_id.(string) == "" { + if vpcID.(string) == "" { log.Printf( "[DEBUG] Not detaching Internet Gateway '%s' as no VPC ID is set", d.Id()) @@ -175,10 +186,10 @@ func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{}) log.Printf( "[INFO] Detaching Internet Gateway '%s' from VPC '%s'", d.Id(), - vpc_id.(string)) + vpcID.(string)) wait := true - _, err := ec2conn.DetachInternetGateway(d.Id(), vpc_id.(string)) + _, err := ec2conn.DetachInternetGateway(d.Id(), vpcID.(string)) if err != nil { ec2err, ok := err.(*ec2.Error) if ok { diff --git a/builtin/providers/aws/resource_aws_internet_gateway_test.go b/builtin/providers/aws/resource_aws_internet_gateway_test.go index f5b1bda25..753fb51d6 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway_test.go +++ b/builtin/providers/aws/resource_aws_internet_gateway_test.go @@ -74,7 +74,8 @@ func TestAccAWSInternetGateway_delete(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccInternetGatewayConfig, - Check: resource.ComposeTestCheckFunc(testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &ig)), + Check: resource.ComposeTestCheckFunc( + testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &ig)), }, resource.TestStep{ Config: testAccNoInternetGatewayConfig, @@ -84,6 +85,33 @@ func TestAccAWSInternetGateway_delete(t *testing.T) { }) } +func TestAccInternetGateway_tags(t *testing.T) { + var v ec2.InternetGateway + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckInternetGatewayDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckInternetGatewayConfigTags, + Check: resource.ComposeTestCheckFunc( + testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v), + ), + }, + + resource.TestStep{ + Config: testAccCheckInternetGatewayConfigTagsUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v), + testAccCheckTags(&v.Tags, "foo", ""), + testAccCheckTags(&v.Tags, "bar", "baz"), + ), + }, + }, + }) +} + func testAccCheckInternetGatewayDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).ec2conn @@ -97,7 +125,7 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error { []string{rs.Primary.ID}, ec2.NewFilter()) if err == nil { if len(resp.InternetGateways) > 0 { - return fmt.Errorf("still exist.") + return fmt.Errorf("still exists") } return nil @@ -172,3 +200,29 @@ resource "aws_internet_gateway" "foo" { vpc_id = "${aws_vpc.bar.id}" } ` + +const testAccCheckInternetGatewayConfigTags = ` +resource "aws_vpc" "foo" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_internet_gateway" "foo" { + vpc_id = "${aws_vpc.foo.id}" + tags { + foo = "bar" + } +} +` + +const testAccCheckInternetGatewayConfigTagsUpdate = ` +resource "aws_vpc" "foo" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_internet_gateway" "foo" { + vpc_id = "${aws_vpc.foo.id}" + tags { + bar = "baz" + } +} +`