diff --git a/aws/data_source_aws_nat_gateway_test.go b/aws/data_source_aws_nat_gateway_test.go index 7fb4ce22fcc..cecf0c73db9 100644 --- a/aws/data_source_aws_nat_gateway_test.go +++ b/aws/data_source_aws_nat_gateway_test.go @@ -78,6 +78,10 @@ resource "aws_nat_gateway" "test" { subnet_id = "${aws_subnet.test.id}" allocation_id = "${aws_eip.test.id}" + tags { + Name = "terraform-testacc-nat-gw-data-source" + } + depends_on = ["aws_internet_gateway.test"] } diff --git a/aws/import_aws_route_table_test.go b/aws/import_aws_route_table_test.go index a8074274027..86af2259d66 100644 --- a/aws/import_aws_route_table_test.go +++ b/aws/import_aws_route_table_test.go @@ -105,6 +105,10 @@ resource "aws_nat_gateway" "nat" { count = "${length(split(",", var.private_subnet_cidrs))}" allocation_id = "${element(aws_eip.nat.*.id, count.index)}" subnet_id = "${aws_subnet.tf_test_subnet.id}" + + tags { + Name = "terraform-testacc-route-table-import-complex-default" + } } resource "aws_route_table" "mod" { diff --git a/aws/resource_aws_internet_gateway_test.go b/aws/resource_aws_internet_gateway_test.go index 720bd480871..9fcb937f992 100644 --- a/aws/resource_aws_internet_gateway_test.go +++ b/aws/resource_aws_internet_gateway_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "log" "testing" "github.com/aws/aws-sdk-go/aws" @@ -11,6 +12,54 @@ import ( "github.com/hashicorp/terraform/terraform" ) +func init() { + resource.AddTestSweepers("aws_internet_gateway", &resource.Sweeper{ + Name: "aws_internet_gateway", + F: testSweepInternetGateways, + }) +} + +func testSweepInternetGateways(region string) error { + client, err := sharedClientForRegion(region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.(*AWSClient).ec2conn + + req := &ec2.DescribeInternetGatewaysInput{ + Filters: []*ec2.Filter{ + { + Name: aws.String("tag-value"), + Values: []*string{ + aws.String("terraform-testacc-*"), + }, + }, + }, + } + resp, err := conn.DescribeInternetGateways(req) + if err != nil { + return fmt.Errorf("Error describing Internet Gateways: %s", err) + } + + if len(resp.InternetGateways) == 0 { + log.Print("[DEBUG] No AWS Internet Gateways to sweep") + return nil + } + + for _, internetGateway := range resp.InternetGateways { + _, err := conn.DeleteInternetGateway(&ec2.DeleteInternetGatewayInput{ + InternetGatewayId: internetGateway.InternetGatewayId, + }) + if err != nil { + return fmt.Errorf( + "Error deleting Internet Gateway (%s): %s", + *internetGateway.InternetGatewayId, err) + } + } + + return nil +} + func TestAccAWSInternetGateway_basic(t *testing.T) { var v, v2 ec2.InternetGateway @@ -102,6 +151,7 @@ func TestAccAWSInternetGateway_tags(t *testing.T) { Config: testAccCheckInternetGatewayConfigTags, Check: resource.ComposeTestCheckFunc( testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v), + testAccCheckTags(&v.Tags, "Name", "terraform-testacc-internet-gateway-tags"), testAccCheckTags(&v.Tags, "foo", "bar"), ), }, @@ -110,6 +160,7 @@ func TestAccAWSInternetGateway_tags(t *testing.T) { Config: testAccCheckInternetGatewayConfigTagsUpdate, Check: resource.ComposeTestCheckFunc( testAccCheckInternetGatewayExists("aws_internet_gateway.foo", &v), + testAccCheckTags(&v.Tags, "Name", "terraform-testacc-internet-gateway-tags"), testAccCheckTags(&v.Tags, "foo", ""), testAccCheckTags(&v.Tags, "bar", "baz"), ), @@ -198,6 +249,9 @@ resource "aws_vpc" "foo" { resource "aws_internet_gateway" "foo" { vpc_id = "${aws_vpc.foo.id}" + tags { + Name = "terraform-testacc-internet-gateway" + } } ` @@ -218,6 +272,9 @@ resource "aws_vpc" "bar" { resource "aws_internet_gateway" "foo" { vpc_id = "${aws_vpc.bar.id}" + tags { + Name = "terraform-testacc-internet-gateway-change-vpc-other" + } } ` @@ -232,6 +289,7 @@ resource "aws_vpc" "foo" { resource "aws_internet_gateway" "foo" { vpc_id = "${aws_vpc.foo.id}" tags { + Name = "terraform-testacc-internet-gateway-tags" foo = "bar" } } @@ -248,6 +306,7 @@ resource "aws_vpc" "foo" { resource "aws_internet_gateway" "foo" { vpc_id = "${aws_vpc.foo.id}" tags { + Name = "terraform-testacc-internet-gateway-tags" bar = "baz" } } diff --git a/aws/resource_aws_nat_gateway_test.go b/aws/resource_aws_nat_gateway_test.go index 31ba3a0507d..f243fff990c 100644 --- a/aws/resource_aws_nat_gateway_test.go +++ b/aws/resource_aws_nat_gateway_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "log" "strings" "testing" @@ -12,6 +13,54 @@ import ( "github.com/hashicorp/terraform/terraform" ) +func init() { + resource.AddTestSweepers("aws_nat_gateway", &resource.Sweeper{ + Name: "aws_nat_gateway", + F: testSweepNatGateways, + }) +} + +func testSweepNatGateways(region string) error { + client, err := sharedClientForRegion(region) + if err != nil { + return fmt.Errorf("error getting client: %s", err) + } + conn := client.(*AWSClient).ec2conn + + req := &ec2.DescribeNatGatewaysInput{ + Filter: []*ec2.Filter{ + { + Name: aws.String("tag-value"), + Values: []*string{ + aws.String("terraform-testacc-*"), + }, + }, + }, + } + resp, err := conn.DescribeNatGateways(req) + if err != nil { + return fmt.Errorf("Error describing NAT Gateways: %s", err) + } + + if len(resp.NatGateways) == 0 { + log.Print("[DEBUG] No AWS NAT Gateways to sweep") + return nil + } + + for _, natGateway := range resp.NatGateways { + _, err := conn.DeleteNatGateway(&ec2.DeleteNatGatewayInput{ + NatGatewayId: natGateway.NatGatewayId, + }) + if err != nil { + return fmt.Errorf( + "Error deleting NAT Gateway (%s): %s", + *natGateway.NatGatewayId, err) + } + } + + return nil +} + func TestAccAWSNatGateway_basic(t *testing.T) { var natGateway ec2.NatGateway @@ -43,6 +92,7 @@ func TestAccAWSNatGateway_tags(t *testing.T) { Config: testAccNatGatewayConfigTags, Check: resource.ComposeTestCheckFunc( testAccCheckNatGatewayExists("aws_nat_gateway.gateway", &natGateway), + testAccCheckTags(&natGateway.Tags, "Name", "terraform-testacc-nat-gw-tags"), testAccCheckTags(&natGateway.Tags, "foo", "bar"), ), }, @@ -51,6 +101,7 @@ func TestAccAWSNatGateway_tags(t *testing.T) { Config: testAccNatGatewayConfigTagsUpdate, Check: resource.ComposeTestCheckFunc( testAccCheckNatGatewayExists("aws_nat_gateway.gateway", &natGateway), + testAccCheckTags(&natGateway.Tags, "Name", "terraform-testacc-nat-gw-tags"), testAccCheckTags(&natGateway.Tags, "foo", ""), testAccCheckTags(&natGateway.Tags, "bar", "baz"), ), @@ -158,6 +209,10 @@ resource "aws_nat_gateway" "gateway" { allocation_id = "${aws_eip.nat_gateway.id}" subnet_id = "${aws_subnet.public.id}" + tags { + Name = "terraform-testacc-nat-gw-basic" + } + depends_on = ["aws_internet_gateway.gw"] } @@ -224,6 +279,7 @@ resource "aws_nat_gateway" "gateway" { subnet_id = "${aws_subnet.public.id}" tags { + Name = "terraform-testacc-nat-gw-tags" foo = "bar" } @@ -293,6 +349,7 @@ resource "aws_nat_gateway" "gateway" { subnet_id = "${aws_subnet.public.id}" tags { + Name = "terraform-testacc-nat-gw-tags" bar = "baz" } diff --git a/aws/resource_aws_vpc_test.go b/aws/resource_aws_vpc_test.go index 8bb3de93283..54550b86b59 100644 --- a/aws/resource_aws_vpc_test.go +++ b/aws/resource_aws_vpc_test.go @@ -17,6 +17,8 @@ func init() { resource.AddTestSweepers("aws_vpc", &resource.Sweeper{ Name: "aws_vpc", Dependencies: []string{ + "aws_internet_gateway", + "aws_nat_gateway", "aws_network_acl", "aws_security_group", "aws_subnet",