From 3accd5485ab523a30c338081d4a49921f9c87208 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Mon, 31 Oct 2016 09:52:38 +0000 Subject: [PATCH] provider/aws: Make iam_user_policy_attachment_test work as expected: (#9733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was failing due to using IAM user `test-name` as it was being used in more than 1 place - this has been replaced by a random user and random policy names now ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSUserPolicyAttachment_basic' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/10/31 08:39:08 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSUserPolicyAttachment_basic -timeout 120m === RUN TestAccAWSUserPolicyAttachment_basic --- PASS: TestAccAWSUserPolicyAttachment_basic (32.04s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 32.053s ``` --- ...rce_aws_iam_user_policy_attachment_test.go | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/builtin/providers/aws/resource_aws_iam_user_policy_attachment_test.go b/builtin/providers/aws/resource_aws_iam_user_policy_attachment_test.go index 86daafeab..8958b5c71 100644 --- a/builtin/providers/aws/resource_aws_iam_user_policy_attachment_test.go +++ b/builtin/providers/aws/resource_aws_iam_user_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 TestAccAWSUserPolicyAttachment_basic(t *testing.T) { var out iam.ListAttachedUserPoliciesOutput + rName := acctest.RandString(10) + policyName1 := fmt.Sprintf("test-policy-%s", acctest.RandString(10)) + policyName2 := fmt.Sprintf("test-policy-%s", acctest.RandString(10)) + policyName3 := fmt.Sprintf("test-policy-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSUserPolicyAttachmentDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccAWSUserPolicyAttachConfig, + { + Config: testAccAWSUserPolicyAttachConfig(rName, policyName1), Check: resource.ComposeTestCheckFunc( testAccCheckAWSUserPolicyAttachmentExists("aws_iam_user_policy_attachment.test-attach", 1, &out), - testAccCheckAWSUserPolicyAttachmentAttributes([]string{"test-policy"}, &out), + testAccCheckAWSUserPolicyAttachmentAttributes([]string{policyName1}, &out), ), }, - resource.TestStep{ - Config: testAccAWSUserPolicyAttachConfigUpdate, + { + Config: testAccAWSUserPolicyAttachConfigUpdate(rName, policyName1, policyName2, policyName3), Check: resource.ComposeTestCheckFunc( testAccCheckAWSUserPolicyAttachmentExists("aws_iam_user_policy_attachment.test-attach", 2, &out), - testAccCheckAWSUserPolicyAttachmentAttributes([]string{"test-policy2", "test-policy3"}, &out), + testAccCheckAWSUserPolicyAttachmentAttributes([]string{policyName2, policyName3}, &out), ), }, }, @@ -88,13 +93,14 @@ func testAccCheckAWSUserPolicyAttachmentAttributes(policies []string, out *iam.L } } -const testAccAWSUserPolicyAttachConfig = ` +func testAccAWSUserPolicyAttachConfig(rName, policyName string) string { + return fmt.Sprintf(` resource "aws_iam_user" "user" { - name = "test-user" + name = "test-user-%s" } resource "aws_iam_policy" "policy" { - name = "test-policy" + name = "%s" description = "A test policy" policy = <