From 5923c7204deb05c7c53ab320c6af5884b71fc94a Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 8 Sep 2018 18:42:10 +0400 Subject: [PATCH 1/3] cover the issues in acceptance test --- aws/resource_aws_iam_policy_test.go | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/aws/resource_aws_iam_policy_test.go b/aws/resource_aws_iam_policy_test.go index a63a75eb6956..15b57f624512 100644 --- a/aws/resource_aws_iam_policy_test.go +++ b/aws/resource_aws_iam_policy_test.go @@ -8,6 +8,7 @@ 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" ) @@ -46,6 +47,26 @@ func TestAWSPolicy_invalidJson(t *testing.T) { }) } +func TestAWSPolicy_checkDescription(t *testing.T) { + var out iam.GetPolicyOutput + rName := acctest.RandString(10) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSPolicyDescriptionCheckConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSPolicyExists("aws_iam_policy.policy", &out), + resource.TestCheckResourceAttrSet("aws_iam_policy.policy", "description"), + ), + }, + }, + }) +} + func testAccCheckAWSPolicyExists(resource string, res *iam.GetPolicyOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resource] @@ -129,3 +150,26 @@ resource "aws_iam_policy" "policy" { EOF } ` + +func testAccAWSPolicyDescriptionCheckConfig(rName string) string { + return fmt.Sprintf(` + resource "aws_iam_policy" "policy" { + name_prefix = "test-policy-%s" + path = "/" + policy = < Date: Sat, 8 Sep 2018 18:50:34 +0400 Subject: [PATCH 2/3] add default value to attr description --- aws/resource_aws_iam_policy.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_iam_policy.go b/aws/resource_aws_iam_policy.go index 7b208cf250eb..aba97953b7e9 100644 --- a/aws/resource_aws_iam_policy.go +++ b/aws/resource_aws_iam_policy.go @@ -28,6 +28,7 @@ func resourceAwsIamPolicy() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, + Default: "Managed by Terraform", }, "path": { Type: schema.TypeString, From a837e891c789ae9834d1f1b0326cf3b089146907 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Wed, 12 Sep 2018 23:59:49 +0400 Subject: [PATCH 3/3] corrections based on PR #5815 feedback --- aws/resource_aws_iam_policy.go | 8 +---- aws/resource_aws_iam_policy_test.go | 45 +---------------------------- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/aws/resource_aws_iam_policy.go b/aws/resource_aws_iam_policy.go index aba97953b7e9..33adf4f5c2eb 100644 --- a/aws/resource_aws_iam_policy.go +++ b/aws/resource_aws_iam_policy.go @@ -28,7 +28,6 @@ func resourceAwsIamPolicy() *schema.Resource { Type: schema.TypeString, ForceNew: true, Optional: true, - Default: "Managed by Terraform", }, "path": { Type: schema.TypeString, @@ -279,12 +278,7 @@ func iamPolicyListVersions(arn string, iamconn *iam.IAM) ([]*iam.PolicyVersion, func readIamPolicy(d *schema.ResourceData, policy *iam.Policy) error { d.SetId(*policy.Arn) - if policy.Description != nil { - // the description isn't present in the response to CreatePolicy. - if err := d.Set("description", policy.Description); err != nil { - return err - } - } + d.Set("description", policy.Description) if err := d.Set("path", policy.Path); err != nil { return err } diff --git a/aws/resource_aws_iam_policy_test.go b/aws/resource_aws_iam_policy_test.go index 15b57f624512..e26a4b57db9a 100644 --- a/aws/resource_aws_iam_policy_test.go +++ b/aws/resource_aws_iam_policy_test.go @@ -8,7 +8,6 @@ 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" ) @@ -27,6 +26,7 @@ func TestAWSPolicy_namePrefix(t *testing.T) { testAccCheckAWSPolicyExists("aws_iam_policy.policy", &out), testAccCheckAWSPolicyGeneratedNamePrefix( "aws_iam_policy.policy", "test-policy-"), + resource.TestCheckResourceAttr("aws_iam_policy.policy", "description", ""), ), }, }, @@ -47,26 +47,6 @@ func TestAWSPolicy_invalidJson(t *testing.T) { }) } -func TestAWSPolicy_checkDescription(t *testing.T) { - var out iam.GetPolicyOutput - rName := acctest.RandString(10) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSPolicyDescriptionCheckConfig(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSPolicyExists("aws_iam_policy.policy", &out), - resource.TestCheckResourceAttrSet("aws_iam_policy.policy", "description"), - ), - }, - }, - }) -} - func testAccCheckAWSPolicyExists(resource string, res *iam.GetPolicyOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resource] @@ -150,26 +130,3 @@ resource "aws_iam_policy" "policy" { EOF } ` - -func testAccAWSPolicyDescriptionCheckConfig(rName string) string { - return fmt.Sprintf(` - resource "aws_iam_policy" "policy" { - name_prefix = "test-policy-%s" - path = "/" - policy = <