-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
data-source/iam_instance_profile: export attributes role_arn and role_name #4300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,8 @@ import ( | |
) | ||
|
||
func TestAccAWSDataSourceIAMInstanceProfile_basic(t *testing.T) { | ||
roleName := fmt.Sprintf("test-datasource-user-%d", acctest.RandInt()) | ||
profileName := fmt.Sprintf("test-datasource-user-%d", acctest.RandInt()) | ||
roleName := fmt.Sprintf("tf-acc-ds-instance-profile-role-%d", acctest.RandInt()) | ||
profileName := fmt.Sprintf("tf-acc-ds-instance-profile-%d", acctest.RandInt()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
|
@@ -20,10 +20,19 @@ func TestAccAWSDataSourceIAMInstanceProfile_basic(t *testing.T) { | |
{ | ||
Config: testAccDatasourceAwsIamInstanceProfileConfig(roleName, profileName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.aws_iam_instance_profile.test", "role_id"), | ||
resource.TestMatchResourceAttr( | ||
"data.aws_iam_instance_profile.test", | ||
"arn", | ||
regexp.MustCompile("^arn:aws:iam::[0-9]{12}:instance-profile/testpath/"+profileName+"$"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adjusting this to be more concise! A maintainability note: we should allow other AWS partitions for acceptance testing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good to know. thanks 😄 |
||
), | ||
resource.TestCheckResourceAttr("data.aws_iam_instance_profile.test", "path", "/testpath/"), | ||
resource.TestMatchResourceAttr("data.aws_iam_instance_profile.test", "arn", | ||
regexp.MustCompile("^arn:aws:iam::[0-9]{12}:instance-profile/testpath/"+profileName+"$")), | ||
resource.TestMatchResourceAttr( | ||
"data.aws_iam_instance_profile.test", | ||
"role_arn", | ||
regexp.MustCompile("^arn:aws: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), | ||
), | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should perform a
len()
test to prevent a panic if for some reasoninstanceProfile.Roles
has no elements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can't always trust aws as we've seen quite a few times 😆