From 6b8633d5f8020a2729d8f5ae02f222ef2709aa13 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 23 Apr 2020 16:04:11 -0700 Subject: [PATCH 1/2] Updates IAM acceptance tests to use ARN testing check functions --- aws/data_source_aws_iam_policy_test.go | 13 ++++++------- aws/data_source_aws_iam_user_test.go | 13 +++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/aws/data_source_aws_iam_policy_test.go b/aws/data_source_aws_iam_policy_test.go index 4628f5f2b1f..361827b2ba9 100644 --- a/aws/data_source_aws_iam_policy_test.go +++ b/aws/data_source_aws_iam_policy_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -10,6 +9,7 @@ import ( ) func TestAccAWSDataSourceIAMPolicy_basic(t *testing.T) { + resourceName := "data.aws_iam_policy.test" policyName := fmt.Sprintf("test-policy-%s", acctest.RandString(10)) resource.ParallelTest(t, resource.TestCase{ @@ -19,12 +19,11 @@ func TestAccAWSDataSourceIAMPolicy_basic(t *testing.T) { { Config: testAccAwsDataSourceIamPolicyConfig(policyName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_iam_policy.test", "name", policyName), - resource.TestCheckResourceAttr("data.aws_iam_policy.test", "description", "My test policy"), - resource.TestCheckResourceAttr("data.aws_iam_policy.test", "path", "/"), - resource.TestCheckResourceAttrSet("data.aws_iam_policy.test", "policy"), - resource.TestMatchResourceAttr("data.aws_iam_policy.test", "arn", - regexp.MustCompile(`^arn:[\w-]+:([a-zA-Z0-9\-])+:([a-z]{2}-(gov-)?[a-z]+-\d{1})?:(\d{12})?:(.*)$`)), + resource.TestCheckResourceAttr(resourceName, "name", policyName), + resource.TestCheckResourceAttr(resourceName, "description", "My test policy"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttrSet(resourceName, "policy"), + resource.TestCheckResourceAttrPair(resourceName, "arn", "aws_iam_policy.test_policy", "arn"), ), }, }, diff --git a/aws/data_source_aws_iam_user_test.go b/aws/data_source_aws_iam_user_test.go index ea44d1c07f8..d92ab2bc631 100644 --- a/aws/data_source_aws_iam_user_test.go +++ b/aws/data_source_aws_iam_user_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -10,6 +9,8 @@ import ( ) func TestAccAWSDataSourceIAMUser_basic(t *testing.T) { + resourceName := "data.aws_iam_user.test" + userName := fmt.Sprintf("test-datasource-user-%d", acctest.RandInt()) resource.ParallelTest(t, resource.TestCase{ @@ -19,11 +20,11 @@ func TestAccAWSDataSourceIAMUser_basic(t *testing.T) { { Config: testAccAwsDataSourceIAMUserConfig(userName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.aws_iam_user.test", "user_id"), - resource.TestCheckResourceAttr("data.aws_iam_user.test", "path", "/"), - resource.TestCheckResourceAttr("data.aws_iam_user.test", "permissions_boundary", ""), - resource.TestCheckResourceAttr("data.aws_iam_user.test", "user_name", userName), - resource.TestMatchResourceAttr("data.aws_iam_user.test", "arn", regexp.MustCompile("^arn:[^:]+:iam::[0-9]{12}:user/"+userName)), + resource.TestCheckResourceAttrPair(resourceName, "user_id", "aws_iam_user.user", "unique_id"), + resource.TestCheckResourceAttr(resourceName, "path", "/"), + resource.TestCheckResourceAttr(resourceName, "permissions_boundary", ""), + resource.TestCheckResourceAttr(resourceName, "user_name", userName), + resource.TestCheckResourceAttrPair(resourceName, "arn", "aws_iam_user.user", "arn"), ), }, }, From ae00149f52b96bf828b745cfe0986e9527f378d8 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 23 Apr 2020 16:06:49 -0700 Subject: [PATCH 2/2] Adds ARN test for IAM instance profile data source --- ...ta_source_aws_iam_instance_profile_test.go | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/aws/data_source_aws_iam_instance_profile_test.go b/aws/data_source_aws_iam_instance_profile_test.go index 46a7580d95c..fb1b0030735 100644 --- a/aws/data_source_aws_iam_instance_profile_test.go +++ b/aws/data_source_aws_iam_instance_profile_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -10,6 +9,8 @@ import ( ) func TestAccAWSDataSourceIAMInstanceProfile_basic(t *testing.T) { + resourceName := "data.aws_iam_instance_profile.test" + roleName := fmt.Sprintf("tf-acc-ds-instance-profile-role-%d", acctest.RandInt()) profileName := fmt.Sprintf("tf-acc-ds-instance-profile-%d", acctest.RandInt()) @@ -20,19 +21,11 @@ func TestAccAWSDataSourceIAMInstanceProfile_basic(t *testing.T) { { Config: testAccDatasourceAwsIamInstanceProfileConfig(roleName, profileName), Check: resource.ComposeTestCheckFunc( - resource.TestMatchResourceAttr( - "data.aws_iam_instance_profile.test", - "arn", - regexp.MustCompile("^arn:[^:]+:iam::[0-9]{12}:instance-profile/testpath/"+profileName+"$"), - ), - resource.TestCheckResourceAttr("data.aws_iam_instance_profile.test", "path", "/testpath/"), - resource.TestMatchResourceAttr( - "data.aws_iam_instance_profile.test", - "role_arn", - regexp.MustCompile("^arn:[^:]+:iam::[0-9]{12}:role/"+roleName+"$"), - ), - resource.TestCheckResourceAttrSet("data.aws_iam_instance_profile.test", "role_id"), - resource.TestCheckResourceAttr("data.aws_iam_instance_profile.test", "role_name", roleName), + resource.TestCheckResourceAttrPair(resourceName, "arn", "aws_iam_instance_profile.test", "arn"), + resource.TestCheckResourceAttr(resourceName, "path", "/testpath/"), + resource.TestCheckResourceAttrPair(resourceName, "role_arn", "aws_iam_role.test", "arn"), + resource.TestCheckResourceAttrPair(resourceName, "role_id", "aws_iam_role.test", "unique_id"), + resource.TestCheckResourceAttr(resourceName, "role_name", roleName), ), }, },