diff --git a/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go b/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go index ecb69f25a..3ce37f1a4 100644 --- a/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go +++ b/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/codedeploy" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" @@ -18,19 +19,21 @@ import ( func TestAccAWSCodeDeployDeploymentGroup_basic(t *testing.T) { var group codedeploy.DeploymentGroupInfo + rName := acctest.RandString(5) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeDeployDeploymentGroupDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroup, + Config: testAccAWSCodeDeployDeploymentGroup(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "app_name", "foo_app"), + "aws_codedeploy_deployment_group.foo", "app_name", "foo_app_"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "deployment_group_name", "foo"), + "aws_codedeploy_deployment_group.foo", "deployment_group_name", "foo_"+rName), resource.TestCheckResourceAttr( "aws_codedeploy_deployment_group.foo", "deployment_config_name", "CodeDeployDefault.OneAtATime"), @@ -45,13 +48,13 @@ func TestAccAWSCodeDeployDeploymentGroup_basic(t *testing.T) { ), }, resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroupModified, + Config: testAccAWSCodeDeployDeploymentGroupModified(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "app_name", "foo_app"), + "aws_codedeploy_deployment_group.foo", "app_name", "foo_app_"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "deployment_group_name", "bar"), + "aws_codedeploy_deployment_group.foo", "deployment_group_name", "bar_"+rName), resource.TestCheckResourceAttr( "aws_codedeploy_deployment_group.foo", "deployment_config_name", "CodeDeployDefault.OneAtATime"), @@ -72,19 +75,21 @@ func TestAccAWSCodeDeployDeploymentGroup_basic(t *testing.T) { func TestAccAWSCodeDeployDeploymentGroup_onPremiseTag(t *testing.T) { var group codedeploy.DeploymentGroupInfo + rName := acctest.RandString(5) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeDeployDeploymentGroupDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroupOnPremiseTags, + Config: testAccAWSCodeDeployDeploymentGroupOnPremiseTags(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "app_name", "foo_app"), + "aws_codedeploy_deployment_group.foo", "app_name", "foo_app_"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo", "deployment_group_name", "foo"), + "aws_codedeploy_deployment_group.foo", "deployment_group_name", "foo_"+rName), resource.TestCheckResourceAttr( "aws_codedeploy_deployment_group.foo", "deployment_config_name", "CodeDeployDefault.OneAtATime"), @@ -105,32 +110,34 @@ func TestAccAWSCodeDeployDeploymentGroup_onPremiseTag(t *testing.T) { func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_basic(t *testing.T) { var group codedeploy.DeploymentGroupInfo + rName := acctest.RandString(5) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeDeployDeploymentGroupDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_create, + Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_create(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo_group", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app"), + "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app-"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group"), + "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group-"+rName), testAccCheckTriggerEvents(&group, "foo-trigger", []string{ "DeploymentFailure", }), ), }, resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_update, + Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_update(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo_group", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app"), + "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app-"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group"), + "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group-"+rName), testAccCheckTriggerEvents(&group, "foo-trigger", []string{ "DeploymentFailure", "DeploymentSuccess", @@ -144,19 +151,21 @@ func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_basic(t *testing.T func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_multiple(t *testing.T) { var group codedeploy.DeploymentGroupInfo + rName := acctest.RandString(5) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSCodeDeployDeploymentGroupDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_createMultiple, + Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_createMultiple(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo_group", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app"), + "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app-"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group"), + "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group-"+rName), testAccCheckTriggerEvents(&group, "foo-trigger", []string{ "DeploymentFailure", }), @@ -164,17 +173,17 @@ func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_multiple(t *testin "InstanceFailure", }), testAccCheckTriggerTargetArn(&group, "bar-trigger", - regexp.MustCompile("^arn:aws:sns:[^:]+:[0-9]{12}:bar-topic$")), + regexp.MustCompile("^arn:aws:sns:[^:]+:[0-9]{12}:bar-topic-"+rName+"$")), ), }, resource.TestStep{ - Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_updateMultiple, + Config: testAccAWSCodeDeployDeploymentGroup_triggerConfiguration_updateMultiple(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo_group", &group), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app"), + "aws_codedeploy_deployment_group.foo_group", "app_name", "foo-app-"+rName), resource.TestCheckResourceAttr( - "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group"), + "aws_codedeploy_deployment_group.foo_group", "deployment_group_name", "foo-group-"+rName), testAccCheckTriggerEvents(&group, "foo-trigger", []string{ "DeploymentFailure", "DeploymentStart", @@ -185,7 +194,7 @@ func TestAccAWSCodeDeployDeploymentGroup_triggerConfiguration_multiple(t *testin "InstanceFailure", }), testAccCheckTriggerTargetArn(&group, "bar-trigger", - regexp.MustCompile("^arn:aws:sns:[^:]+:[0-9]{12}:baz-topic$")), + regexp.MustCompile("^arn:aws:sns:[^:]+:[0-9]{12}:baz-topic-"+rName+"$")), ), }, }, @@ -422,13 +431,14 @@ func testAccCheckAWSCodeDeployDeploymentGroupExists(name string, group *codedepl } } -var testAccAWSCodeDeployDeploymentGroup = ` +func testAccAWSCodeDeployDeploymentGroup(rName string) string { + return fmt.Sprintf(` resource "aws_codedeploy_app" "foo_app" { - name = "foo_app" + name = "foo_app_%s" } resource "aws_iam_role_policy" "foo_policy" { - name = "foo_policy" + name = "foo_policy_%s" role = "${aws_iam_role.foo_role.id}" policy = <