Merge pull request #4531 from hashicorp/b-aws-resources-tests

provider/aws: Clean up OpsWorks tests
This commit is contained in:
Clint 2016-01-06 15:40:59 -06:00
commit 98703490bc
2 changed files with 39 additions and 13 deletions

View File

@ -4,6 +4,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -131,12 +134,31 @@ func TestAccAWSOpsworksCustomLayer(t *testing.T) {
} }
func testAccCheckAwsOpsworksCustomLayerDestroy(s *terraform.State) error { func testAccCheckAwsOpsworksCustomLayerDestroy(s *terraform.State) error {
if len(s.RootModule().Resources) > 0 { opsworksconn := testAccProvider.Meta().(*AWSClient).opsworksconn
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources) for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_opsworks_custom_layer" {
continue
}
req := &opsworks.DescribeLayersInput{
LayerIds: []*string{
aws.String(rs.Primary.ID),
},
} }
_, err := opsworksconn.DescribeLayers(req)
if err != nil {
if awserr, ok := err.(awserr.Error); ok {
if awserr.Code() == "ResourceNotFoundException" {
// not found, good to go
return nil return nil
} }
}
return err
}
}
return fmt.Errorf("Fall through error on OpsWorks custom layer test")
}
var testAccAwsOpsworksCustomLayerSecurityGroups = ` var testAccAwsOpsworksCustomLayerSecurityGroups = `
resource "aws_security_group" "tf-ops-acc-layer1" { resource "aws_security_group" "tf-ops-acc-layer1" {
@ -160,6 +182,10 @@ resource "aws_security_group" "tf-ops-acc-layer2" {
` `
var testAccAwsOpsworksCustomLayerConfigCreate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + ` var testAccAwsOpsworksCustomLayerConfigCreate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + `
provider "aws" {
region = "us-east-1"
}
resource "aws_opsworks_custom_layer" "tf-acc" { resource "aws_opsworks_custom_layer" "tf-acc" {
stack_id = "${aws_opsworks_stack.tf-acc.id}" stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "tf-ops-acc-custom-layer" name = "tf-ops-acc-custom-layer"

View File

@ -91,10 +91,10 @@ resource "aws_iam_instance_profile" "opsworks_instance" {
var testAccAwsOpsworksStackConfigNoVpcCreate = testAccAwsOpsworksStackIamConfig + ` var testAccAwsOpsworksStackConfigNoVpcCreate = testAccAwsOpsworksStackIamConfig + `
resource "aws_opsworks_stack" "tf-acc" { resource "aws_opsworks_stack" "tf-acc" {
name = "tf-opsworks-acc" name = "tf-opsworks-acc"
region = "us-west-2" region = "us-east-1"
service_role_arn = "${aws_iam_role.opsworks_service.arn}" service_role_arn = "${aws_iam_role.opsworks_service.arn}"
default_instance_profile_arn = "${aws_iam_instance_profile.opsworks_instance.arn}" default_instance_profile_arn = "${aws_iam_instance_profile.opsworks_instance.arn}"
default_availability_zone = "us-west-2a" default_availability_zone = "us-east-1c"
default_os = "Amazon Linux 2014.09" default_os = "Amazon Linux 2014.09"
default_root_device_type = "ebs" default_root_device_type = "ebs"
custom_json = "{\"key\": \"value\"}" custom_json = "{\"key\": \"value\"}"
@ -105,10 +105,10 @@ resource "aws_opsworks_stack" "tf-acc" {
var testAccAWSOpsworksStackConfigNoVpcUpdate = testAccAwsOpsworksStackIamConfig + ` var testAccAWSOpsworksStackConfigNoVpcUpdate = testAccAwsOpsworksStackIamConfig + `
resource "aws_opsworks_stack" "tf-acc" { resource "aws_opsworks_stack" "tf-acc" {
name = "tf-opsworks-acc" name = "tf-opsworks-acc"
region = "us-west-2" region = "us-east-1"
service_role_arn = "${aws_iam_role.opsworks_service.arn}" service_role_arn = "${aws_iam_role.opsworks_service.arn}"
default_instance_profile_arn = "${aws_iam_instance_profile.opsworks_instance.arn}" default_instance_profile_arn = "${aws_iam_instance_profile.opsworks_instance.arn}"
default_availability_zone = "us-west-2a" default_availability_zone = "us-east-1c"
default_os = "Amazon Linux 2014.09" default_os = "Amazon Linux 2014.09"
default_root_device_type = "ebs" default_root_device_type = "ebs"
custom_json = "{\"key\": \"value\"}" custom_json = "{\"key\": \"value\"}"
@ -153,11 +153,11 @@ resource "aws_vpc" "tf-acc" {
resource "aws_subnet" "tf-acc" { resource "aws_subnet" "tf-acc" {
vpc_id = "${aws_vpc.tf-acc.id}" vpc_id = "${aws_vpc.tf-acc.id}"
cidr_block = "${aws_vpc.tf-acc.cidr_block}" cidr_block = "${aws_vpc.tf-acc.cidr_block}"
availability_zone = "us-west-2a" availability_zone = "us-east-1c"
} }
resource "aws_opsworks_stack" "tf-acc" { resource "aws_opsworks_stack" "tf-acc" {
name = "tf-opsworks-acc" name = "tf-opsworks-acc"
region = "us-west-2" region = "us-east-1"
vpc_id = "${aws_vpc.tf-acc.id}" vpc_id = "${aws_vpc.tf-acc.id}"
default_subnet_id = "${aws_subnet.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}"
service_role_arn = "${aws_iam_role.opsworks_service.arn}" service_role_arn = "${aws_iam_role.opsworks_service.arn}"
@ -177,11 +177,11 @@ resource "aws_vpc" "tf-acc" {
resource "aws_subnet" "tf-acc" { resource "aws_subnet" "tf-acc" {
vpc_id = "${aws_vpc.tf-acc.id}" vpc_id = "${aws_vpc.tf-acc.id}"
cidr_block = "${aws_vpc.tf-acc.cidr_block}" cidr_block = "${aws_vpc.tf-acc.cidr_block}"
availability_zone = "us-west-2a" availability_zone = "us-east-1c"
} }
resource "aws_opsworks_stack" "tf-acc" { resource "aws_opsworks_stack" "tf-acc" {
name = "tf-opsworks-acc" name = "tf-opsworks-acc"
region = "us-west-2" region = "us-east-1"
vpc_id = "${aws_vpc.tf-acc.id}" vpc_id = "${aws_vpc.tf-acc.id}"
default_subnet_id = "${aws_subnet.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}"
service_role_arn = "${aws_iam_role.opsworks_service.arn}" service_role_arn = "${aws_iam_role.opsworks_service.arn}"
@ -235,7 +235,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsCreate = resource.ComposeTestCheckF
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc", "aws_opsworks_stack.tf-acc",
"default_availability_zone", "default_availability_zone",
"us-west-2a", "us-east-1c",
), ),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc", "aws_opsworks_stack.tf-acc",
@ -273,7 +273,7 @@ var testAccAwsOpsworksStackCheckResourceAttrsUpdate = resource.ComposeTestCheckF
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc", "aws_opsworks_stack.tf-acc",
"default_availability_zone", "default_availability_zone",
"us-west-2a", "us-east-1c",
), ),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"aws_opsworks_stack.tf-acc", "aws_opsworks_stack.tf-acc",