Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service/iam: Update acceptance tests to use ARN testing check functions #12981

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions aws/data_source_aws_iam_instance_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

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())

Expand All @@ -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),
),
},
},
Expand Down
13 changes: 6 additions & 7 deletions aws/data_source_aws_iam_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

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{
Expand All @@ -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"),
),
},
},
Expand Down
13 changes: 7 additions & 6 deletions aws/data_source_aws_iam_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

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{
Expand All @@ -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"),
),
},
},
Expand Down