From d149602720f1920358dfcfca16c4c09726755541 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 14 Sep 2018 12:49:04 -0400 Subject: [PATCH] resource/aws_iam_policy: Ensure description is properly read during creation This resource was previously not following best practices of calling the read function after creation. Now it will read back information from the API, which tangentally fixes the description not being available in the CreatePolicy response. Changes: * Create separate acceptance tests for all arguments * Call read function after create and update functions * Create `testAccCheckResourceAttrGlobalARN` for checking global ARN attributes * Remove extraneous aws/import_aws_iam_policy_test.go Previously (before code updates): ``` === RUN TestAccAWSIAMPolicy_basic --- PASS: TestAccAWSIAMPolicy_basic (10.15s) === RUN TestAccAWSIAMPolicy_description --- FAIL: TestAccAWSIAMPolicy_description (5.06s) testing.go:527: Step 0 error: Check failed: Check 2/2 error: aws_iam_policy.test: Attribute 'description' expected "description1", got "" === RUN TestAccAWSIAMPolicy_namePrefix --- PASS: TestAccAWSIAMPolicy_namePrefix (9.72s) === RUN TestAccAWSIAMPolicy_path --- PASS: TestAccAWSIAMPolicy_path (9.85s) === RUN TestAccAWSIAMPolicy_policy --- PASS: TestAccAWSIAMPolicy_policy (13.49s) ``` Now: ``` === RUN TestAccAWSIAMPolicy_basic --- PASS: TestAccAWSIAMPolicy_basic (10.29s) === RUN TestAccAWSIAMPolicy_description --- PASS: TestAccAWSIAMPolicy_description (8.00s) === RUN TestAccAWSIAMPolicy_namePrefix --- PASS: TestAccAWSIAMPolicy_namePrefix (9.15s) === RUN TestAccAWSIAMPolicy_path --- PASS: TestAccAWSIAMPolicy_path (9.25s) === RUN TestAccAWSIAMPolicy_policy --- PASS: TestAccAWSIAMPolicy_policy (15.21s) ``` --- aws/import_aws_iam_policy_test.go | 88 ---------- aws/provider_test.go | 13 ++ aws/resource_aws_iam_policy.go | 123 +++++++++----- aws/resource_aws_iam_policy_test.go | 254 +++++++++++++++++++++------- 4 files changed, 286 insertions(+), 192 deletions(-) delete mode 100644 aws/import_aws_iam_policy_test.go diff --git a/aws/import_aws_iam_policy_test.go b/aws/import_aws_iam_policy_test.go deleted file mode 100644 index 2dbd553bda7..00000000000 --- a/aws/import_aws_iam_policy_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package aws - -import ( - "fmt" - "testing" - - "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/resource" - "github.com/hashicorp/terraform/terraform" -) - -func testAccAwsIamPolicyConfig(suffix string) string { - return fmt.Sprintf(` -resource "aws_iam_policy" "test_%[1]s" { - name = "test_policy_%[1]s" - path = "/" - description = "My test policy" - policy = <