Adding tags support to Internet Gateway resource
This commit is contained in:
parent
f61b7af815
commit
9fd59f09e2
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue