From e2a7d4d98bc0d00f2b62e2852742208fffd08a84 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 7 Jan 2016 11:48:53 -0600 Subject: [PATCH 1/3] provider/aws: Update testAccCheckAWSVpcPeeringConnectionDestroy to correctly check the destroyed state --- ...esource_aws_vpc_peering_connection_test.go | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go index 7e85659f2..6393d4564 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -70,14 +70,32 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { VpcPeeringConnectionIds: []*string{aws.String(rs.Primary.ID)}, }) - if err == nil { - if len(describe.VpcPeeringConnections) != 0 { - return fmt.Errorf("vpc peering connection still exists") + if err != nil { + return err + } + + var pc *ec2.VpcPeeringConnection + for _, c := range describe.VpcPeeringConnections { + if rs.Primary.ID == *c.VpcPeeringConnectionId { + pc = c } } + + if pc == nil { + // not found + return nil + } + + if pc.Status != nil { + if *pc.Status.Code == "deleted" { + return nil + } + return fmt.Errorf("Found vpc peering connection in unexpected state: %s", pc) + } + } - return nil + return fmt.Errorf("Fall through error for testAccCheckAWSVpcPeeringConnectionDestroy") } func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc { From dcce2aa4791b0d393b067ce85595db62ef6ff6e1 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 7 Jan 2016 14:16:41 -0600 Subject: [PATCH 2/3] providers/aws: Update OpsWorks tests to inject the expected availability zone, based on if we are testing vpc or not --- .../aws/resource_aws_opsworks_stack_test.go | 225 +++++++++--------- 1 file changed, 117 insertions(+), 108 deletions(-) diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index 97efcdd66..26a72a769 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "log" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -132,11 +133,11 @@ func TestAccAWSOpsworksStackNoVpc(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAwsOpsworksStackConfigNoVpcCreate, - Check: testAccAwsOpsworksStackCheckResourceAttrsCreate, + Check: testAccAwsOpsworksStackCheckResourceAttrsCreate("us-east-1c"), }, resource.TestStep{ Config: testAccAWSOpsworksStackConfigNoVpcUpdate, - Check: testAccAwsOpsworksStackCheckResourceAttrsUpdate, + Check: testAccAwsOpsworksStackCheckResourceAttrsUpdate("us-east-1c"), }, }, }) @@ -153,11 +154,11 @@ resource "aws_vpc" "tf-acc" { resource "aws_subnet" "tf-acc" { vpc_id = "${aws_vpc.tf-acc.id}" cidr_block = "${aws_vpc.tf-acc.cidr_block}" - availability_zone = "us-east-1c" + availability_zone = "us-west-2a" } resource "aws_opsworks_stack" "tf-acc" { name = "tf-opsworks-acc" - region = "us-east-1" + region = "us-west-2" vpc_id = "${aws_vpc.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}" service_role_arn = "${aws_iam_role.opsworks_service.arn}" @@ -177,11 +178,11 @@ resource "aws_vpc" "tf-acc" { resource "aws_subnet" "tf-acc" { vpc_id = "${aws_vpc.tf-acc.id}" cidr_block = "${aws_vpc.tf-acc.cidr_block}" - availability_zone = "us-east-1c" + availability_zone = "us-west-2a" } resource "aws_opsworks_stack" "tf-acc" { name = "tf-opsworks-acc" - region = "us-east-1" + region = "us-west-2" vpc_id = "${aws_vpc.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}" service_role_arn = "${aws_iam_role.opsworks_service.arn}" @@ -209,12 +210,12 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccAwsOpsworksStackConfigVpcCreate, - Check: testAccAwsOpsworksStackCheckResourceAttrsCreate, + Check: testAccAwsOpsworksStackCheckResourceAttrsCreate("us-west-2a"), }, resource.TestStep{ Config: testAccAWSOpsworksStackConfigVpcUpdate, Check: resource.ComposeTestCheckFunc( - testAccAwsOpsworksStackCheckResourceAttrsUpdate, + testAccAwsOpsworksStackCheckResourceAttrsUpdate("us-west-2a"), testAccAwsOpsworksCheckVpc, ), }, @@ -226,106 +227,110 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) { //// Checkers and Utilities //////////////////////////// -var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "name", - "tf-opsworks-acc", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_availability_zone", - "us-east-1c", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_os", - "Amazon Linux 2014.09", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_root_device_type", - "ebs", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "custom_json", - `{"key": "value"}`, - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "configuration_manager_version", - "11.10", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "use_opsworks_security_groups", - "false", - ), -) +func testAccAwsOpsworksStackCheckResourceAttrsCreate(zone string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "name", + "tf-opsworks-acc", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_availability_zone", + zone, + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_os", + "Amazon Linux 2014.09", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_root_device_type", + "ebs", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "custom_json", + `{"key": "value"}`, + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "configuration_manager_version", + "11.10", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "use_opsworks_security_groups", + "false", + ), + ) +} -var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "name", - "tf-opsworks-acc", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_availability_zone", - "us-east-1c", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_os", - "Amazon Linux 2014.09", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "default_root_device_type", - "ebs", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "custom_json", - `{"key": "value"}`, - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "configuration_manager_version", - "11.10", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "use_opsworks_security_groups", - "false", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "use_custom_cookbooks", - "true", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "manage_berkshelf", - "true", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "custom_cookbooks_source.0.type", - "git", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "custom_cookbooks_source.0.revision", - "master", - ), - resource.TestCheckResourceAttr( - "aws_opsworks_stack.tf-acc", - "custom_cookbooks_source.0.url", - "https://github.com/aws/opsworks-example-cookbooks.git", - ), -) +func testAccAwsOpsworksStackCheckResourceAttrsUpdate(zone string) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "name", + "tf-opsworks-acc", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_availability_zone", + zone, + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_os", + "Amazon Linux 2014.09", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "default_root_device_type", + "ebs", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "custom_json", + `{"key": "value"}`, + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "configuration_manager_version", + "11.10", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "use_opsworks_security_groups", + "false", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "use_custom_cookbooks", + "true", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "manage_berkshelf", + "true", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "custom_cookbooks_source.0.type", + "git", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "custom_cookbooks_source.0.revision", + "master", + ), + resource.TestCheckResourceAttr( + "aws_opsworks_stack.tf-acc", + "custom_cookbooks_source.0.url", + "https://github.com/aws/opsworks-example-cookbooks.git", + ), + ) +} func testAccAwsOpsworksCheckVpc(s *terraform.State) error { rs, ok := s.RootModule().Resources["aws_opsworks_stack.tf-acc"] @@ -371,7 +376,7 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error { }, } - _, err := opsworksconn.DescribeStacks(req) + r, err := opsworksconn.DescribeStacks(req) if err != nil { if awserr, ok := err.(awserr.Error); ok { if awserr.Code() == "ResourceNotFoundException" { @@ -382,6 +387,10 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error { return err } + if r != nil { + log.Printf("\n---\nStack response: %s\n---\n", r) + } + } return fmt.Errorf("Fall through error for OpsWorks stack test") } From 9a4f0a06b3494284bad1aeff8e72fcc471c7bec0 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 7 Jan 2016 15:00:55 -0600 Subject: [PATCH 3/3] clean up debugging --- builtin/providers/aws/resource_aws_opsworks_stack_test.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index 26a72a769..ba34663d4 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "log" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -376,7 +375,7 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error { }, } - r, err := opsworksconn.DescribeStacks(req) + _, err := opsworksconn.DescribeStacks(req) if err != nil { if awserr, ok := err.(awserr.Error); ok { if awserr.Code() == "ResourceNotFoundException" { @@ -386,11 +385,6 @@ func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error { } return err } - - if r != nil { - log.Printf("\n---\nStack response: %s\n---\n", r) - } - } return fmt.Errorf("Fall through error for OpsWorks stack test") }