Merge branch 'robzienert-add-ig-tags'

This commit is contained in:
Mitchell Hashimoto 2015-01-10 15:28:27 -08:00
commit 2c3b7c492d
2 changed files with 71 additions and 6 deletions

View File

@ -22,6 +22,7 @@ func resourceAwsInternetGateway() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, 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("vpc_id", ig.Attachments[0].VpcId)
} }
d.Set("tags", tagsToMap(ig.Tags))
return nil 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 return nil
} }
@ -163,9 +174,9 @@ func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{})
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2conn
// Get the old VPC ID to detach from // 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( log.Printf(
"[DEBUG] Not detaching Internet Gateway '%s' as no VPC ID is set", "[DEBUG] Not detaching Internet Gateway '%s' as no VPC ID is set",
d.Id()) d.Id())
@ -175,10 +186,10 @@ func resourceAwsInternetGatewayDetach(d *schema.ResourceData, meta interface{})
log.Printf( log.Printf(
"[INFO] Detaching Internet Gateway '%s' from VPC '%s'", "[INFO] Detaching Internet Gateway '%s' from VPC '%s'",
d.Id(), d.Id(),
vpc_id.(string)) vpcID.(string))
wait := true wait := true
_, err := ec2conn.DetachInternetGateway(d.Id(), vpc_id.(string)) _, err := ec2conn.DetachInternetGateway(d.Id(), vpcID.(string))
if err != nil { if err != nil {
ec2err, ok := err.(*ec2.Error) ec2err, ok := err.(*ec2.Error)
if ok { if ok {

View File

@ -74,7 +74,8 @@ func TestAccAWSInternetGateway_delete(t *testing.T) {
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccInternetGatewayConfig, Config: testAccInternetGatewayConfig,
Check: resource.ComposeTestCheckFunc(testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &ig)), Check: resource.ComposeTestCheckFunc(
testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &ig)),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccNoInternetGatewayConfig, 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 { func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2conn
@ -97,7 +125,7 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
[]string{rs.Primary.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.InternetGateways) > 0 { if len(resp.InternetGateways) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("still exists")
} }
return nil return nil
@ -172,3 +200,29 @@ resource "aws_internet_gateway" "foo" {
vpc_id = "${aws_vpc.bar.id}" 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"
}
}
`