diff --git a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go index fa2e7f3e1..191a49556 100644 --- a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go @@ -7,6 +7,7 @@ import ( "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/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -15,13 +16,14 @@ import ( // and `aws-opsworks-service-role`. func TestAccAWSOpsworksCustomLayer(t *testing.T) { + stackName := fmt.Sprintf("tf-opsworks-acc-%d", acctest.RandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAwsOpsworksCustomLayerConfigCreate, + Config: testAccAwsOpsworksCustomLayerConfigCreate(stackName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "aws_opsworks_custom_layer.tf-acc", "name", "tf-ops-acc-custom-layer", @@ -68,7 +70,7 @@ func TestAccAWSOpsworksCustomLayer(t *testing.T) { ), }, resource.TestStep{ - Config: testAccAwsOpsworksCustomLayerConfigUpdate, + Config: testAccAwsOpsworksCustomLayerConfigUpdate(stackName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "aws_opsworks_custom_layer.tf-acc", "name", "tf-ops-acc-custom-layer", @@ -160,9 +162,10 @@ func testAccCheckAwsOpsworksCustomLayerDestroy(s *terraform.State) error { return fmt.Errorf("Fall through error on OpsWorks custom layer test") } -var testAccAwsOpsworksCustomLayerSecurityGroups = ` +func testAccAwsOpsworksCustomLayerSecurityGroups(name string) string { + return fmt.Sprintf(` resource "aws_security_group" "tf-ops-acc-layer1" { - name = "tf-ops-acc-layer1" + name = "%s-layer1" ingress { from_port = 8 to_port = -1 @@ -171,17 +174,18 @@ resource "aws_security_group" "tf-ops-acc-layer1" { } } resource "aws_security_group" "tf-ops-acc-layer2" { - name = "tf-ops-acc-layer2" + name = "%s-layer2" ingress { from_port = 8 to_port = -1 protocol = "icmp" cidr_blocks = ["0.0.0.0/0"] } +}`, name) } -` -var testAccAwsOpsworksCustomLayerConfigCreate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + ` +func testAccAwsOpsworksCustomLayerConfigCreate(name string) string { + return fmt.Sprintf(` provider "aws" { region = "us-east-1" } @@ -209,9 +213,16 @@ resource "aws_opsworks_custom_layer" "tf-acc" { raid_level = 0 } } -` -var testAccAwsOpsworksCustomLayerConfigUpdate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + ` +%s + +%s + +`, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name)) +} + +func testAccAwsOpsworksCustomLayerConfigUpdate(name string) string { + return fmt.Sprintf(` provider "aws" { region = "us-east-1" } @@ -258,4 +269,10 @@ resource "aws_opsworks_custom_layer" "tf-acc" { iops = 3000 } } -` + +%s + +%s + +`, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name)) +} diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index ba34663d4..d3e8334fd 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -12,209 +13,44 @@ import ( "github.com/aws/aws-sdk-go/service/opsworks" ) -////////////////////////////////////////////////// -//// Helper configs for the necessary IAM objects -////////////////////////////////////////////////// - -var testAccAwsOpsworksStackIamConfig = ` -resource "aws_iam_role" "opsworks_service" { - name = "terraform_testacc_opsworks_service" - assume_role_policy = <