diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go index bdb9a4905..6f6b9c111 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 } @@ -179,9 +190,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()) @@ -191,10 +202,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 47a57c6a4..b576cdb9d 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway_test.go +++ b/builtin/providers/aws/resource_aws_internet_gateway_test.go @@ -54,6 +54,33 @@ func TestAccAWSInternetGateway(t *testing.T) { }) } +func testAccInternetGatewayTags(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 @@ -67,7 +94,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 @@ -136,3 +163,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" + } +} +`