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), ), }, }, 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"), ), }, },