From ea40ef9596bc3b4859edb599c1ee3c4ebf8b5b91 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 22 Mar 2017 20:02:12 -0400 Subject: [PATCH] provider/aws: Update IAM Role Policy Attachment Acctests Leaked resources may prevent this resource from correctly passing acceptance tests. Seeding the policy names with random integer suffixes allows tests to pass regardless of resource leaks. ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSRolePolicyAttachment_basic' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/22 19:58:58 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSRolePolicyAttachment_basic -timeout 120m === RUN TestAccAWSRolePolicyAttachment_basic --- PASS: TestAccAWSRolePolicyAttachment_basic (31.98s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 31.989s ``` --- ...rce_aws_iam_role_policy_attachment_test.go | 229 +++++++++--------- 1 file changed, 118 insertions(+), 111 deletions(-) diff --git a/builtin/providers/aws/resource_aws_iam_role_policy_attachment_test.go b/builtin/providers/aws/resource_aws_iam_role_policy_attachment_test.go index d1b4ef6e18..73c051b301 100644 --- a/builtin/providers/aws/resource_aws_iam_role_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_role_policy_attachment_test.go @@ -7,30 +7,35 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/iam" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) func TestAccAWSRolePolicyAttachment_basic(t *testing.T) { var out iam.ListAttachedRolePoliciesOutput + rInt := acctest.RandInt() + testPolicy := fmt.Sprintf("test-policy-%d", rInt) + testPolicy2 := fmt.Sprintf("test-policy2-%d", rInt) + testPolicy3 := fmt.Sprintf("test-policy3-%d", rInt) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSRolePolicyAttachmentDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccAWSRolePolicyAttachConfig, + { + Config: testAccAWSRolePolicyAttachConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 1, &out), - testAccCheckAWSRolePolicyAttachmentAttributes([]string{"test-policy"}, &out), + testAccCheckAWSRolePolicyAttachmentAttributes([]string{testPolicy}, &out), ), }, - resource.TestStep{ - Config: testAccAWSRolePolicyAttachConfigUpdate, + { + Config: testAccAWSRolePolicyAttachConfigUpdate(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckAWSRolePolicyAttachmentExists("aws_iam_role_policy_attachment.test-attach", 2, &out), - testAccCheckAWSRolePolicyAttachmentAttributes([]string{"test-policy2", "test-policy3"}, &out), + testAccCheckAWSRolePolicyAttachmentAttributes([]string{testPolicy2, testPolicy3}, &out), ), }, }, @@ -88,135 +93,137 @@ func testAccCheckAWSRolePolicyAttachmentAttributes(policies []string, out *iam.L } } -const testAccAWSRolePolicyAttachConfig = ` -resource "aws_iam_role" "role" { - name = "test-role" - assume_role_policy = <