providers/aws: Update OpsWorks tests to inject the expected availability zone, based on if we are testing vpc or not

This commit is contained in:
clint shryock 2016-01-07 14:16:41 -06:00
parent e2a7d4d98b
commit dcce2aa479
1 changed files with 117 additions and 108 deletions

View File

@ -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,7 +227,8 @@ func TestAccAWSOpsworksStackVpc(t *testing.T) {
//// Checkers and Utilities
////////////////////////////
var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckFunc(
func testAccAwsOpsworksStackCheckResourceAttrsCreate(zone string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
"name",
@ -235,7 +237,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckF
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
"default_availability_zone",
"us-east-1c",
zone,
),
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
@ -263,8 +265,10 @@ var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckF
"false",
),
)
}
var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckFunc(
func testAccAwsOpsworksStackCheckResourceAttrsUpdate(zone string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
"name",
@ -273,7 +277,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckF
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
"default_availability_zone",
"us-east-1c",
zone,
),
resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc",
@ -326,6 +330,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckF
"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")
}