From fdc17c8d704593ac54f986c1e44dc2087822fde0 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Wed, 22 Mar 2017 09:06:23 -0400 Subject: [PATCH] provider/aws: Update IAM Group+User Policy Tests (#12950) Updates the IAM Group Policy and IAM User Policy acceptance tests with random integer seeds. Currently acceptance tests for these two resources are failing from leaked resources, adding distint naming should allow tests to pass regardless of parallel tests being ran or any resource leaks. ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSIAMUserPolicy' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/22 00:19:13 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSIAMUserPolicy -timeout 120m === RUN TestAccAWSIAMUserPolicy_basic --- PASS: TestAccAWSIAMUserPolicy_basic (22.54s) === RUN TestAccAWSIAMUserPolicy_namePrefix --- PASS: TestAccAWSIAMUserPolicy_namePrefix (12.49s) === RUN TestAccAWSIAMUserPolicy_generatedName --- PASS: TestAccAWSIAMUserPolicy_generatedName (13.13s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 48.191s ``` ``` $ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSIAMGroupPolicy' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/22 00:24:08 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSIAMGroupPolicy -timeout 120m === RUN TestAccAWSIAMGroupPolicy_basic --- PASS: TestAccAWSIAMGroupPolicy_basic (23.89s) === RUN TestAccAWSIAMGroupPolicy_namePrefix --- PASS: TestAccAWSIAMGroupPolicy_namePrefix (12.07s) === RUN TestAccAWSIAMGroupPolicy_generatedName --- PASS: TestAccAWSIAMGroupPolicy_generatedName (13.15s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 49.140s ``` --- .../aws/resource_aws_iam_group_policy_test.go | 148 +++++++++--------- .../aws/resource_aws_iam_user_policy_test.go | 115 ++++++++------ 2 files changed, 141 insertions(+), 122 deletions(-) diff --git a/builtin/providers/aws/resource_aws_iam_group_policy_test.go b/builtin/providers/aws/resource_aws_iam_group_policy_test.go index c1281f6417..6e33cd4844 100644 --- a/builtin/providers/aws/resource_aws_iam_group_policy_test.go +++ b/builtin/providers/aws/resource_aws_iam_group_policy_test.go @@ -7,18 +7,20 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "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 TestAccAWSIAMGroupPolicy_basic(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckIAMGroupPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccIAMGroupPolicyConfig, + { + Config: testAccIAMGroupPolicyConfig(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckIAMGroupPolicy( "aws_iam_group.group", @@ -26,8 +28,8 @@ func TestAccAWSIAMGroupPolicy_basic(t *testing.T) { ), ), }, - resource.TestStep{ - Config: testAccIAMGroupPolicyConfigUpdate, + { + Config: testAccIAMGroupPolicyConfigUpdate(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckIAMGroupPolicy( "aws_iam_group.group", @@ -40,14 +42,15 @@ func TestAccAWSIAMGroupPolicy_basic(t *testing.T) { } func TestAccAWSIAMGroupPolicy_namePrefix(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_iam_group_policy.test", Providers: testAccProviders, CheckDestroy: testAccCheckIAMGroupPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccIAMGroupPolicyConfig_namePrefix, + { + Config: testAccIAMGroupPolicyConfig_namePrefix(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckIAMGroupPolicy( "aws_iam_group.test", @@ -60,14 +63,15 @@ func TestAccAWSIAMGroupPolicy_namePrefix(t *testing.T) { } func TestAccAWSIAMGroupPolicy_generatedName(t *testing.T) { + rInt := acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_iam_group_policy.test", Providers: testAccProviders, CheckDestroy: testAccCheckIAMGroupPolicyDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccIAMGroupPolicyConfig_generatedName, + { + Config: testAccIAMGroupPolicyConfig_generatedName(rInt), Check: resource.ComposeTestCheckFunc( testAccCheckIAMGroupPolicy( "aws_iam_group.test", @@ -142,86 +146,90 @@ func testAccCheckIAMGroupPolicy( } } -const testAccIAMGroupPolicyConfig = ` -resource "aws_iam_group" "group" { - name = "test_group" - path = "/" -} +func testAccIAMGroupPolicyConfig(rInt int) string { + return fmt.Sprintf(` + resource "aws_iam_group" "group" { + name = "test_group_%d" + path = "/" + } -resource "aws_iam_group_policy" "foo" { - name = "foo_policy" - group = "${aws_iam_group.group.name}" - policy = <