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

data-source/iam_instance_profile: export attributes role_arn and role_name #4300

Merged

Conversation

loivis
Copy link
Contributor

@loivis loivis commented Apr 21, 2018

fix #4080

As arn and name are most likely concerned when reading instance profile.

  make fmt; and echo > aws/debug.log ; and make testacc TEST=./aws TESTARGS='-run=TestAccAWSDataSourceIAMInstanceProfile_basic'
gofmt -w $(find . -name '*.go' |grep -v vendor)
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSDataSourceIAMInstanceProfile_basic -timeout 120m
=== RUN   TestAccAWSDataSourceIAMInstanceProfile_basic
--- PASS: TestAccAWSDataSourceIAMInstanceProfile_basic (41.35s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	41.413s

@ghost ghost added the size/S Managed by automation to categorize the size of a PR. label Apr 21, 2018
@loivis loivis force-pushed the 4080-ds-iam-instance-profile-export-role-name branch from 23f69c7 to 7992cf3 Compare April 21, 2018 09:04
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Apr 21, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! 😄 LGTM and I'll fix the two items below on merge.

=== RUN   TestAccAWSDataSourceIAMInstanceProfile_basic
--- PASS: TestAccAWSDataSourceIAMInstanceProfile_basic (12.58s)

for _, r := range instanceProfile.Roles {
d.Set("role_id", r.RoleId)
}
// it's guaranteed that instanceProfile.Roles exists and has one element
Copy link
Contributor

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 reason instanceProfile.Roles has no elements.

if len(instanceProfile.Roles) > 0 {
  role := instanceProfile.Roles[0]
  d.Set("role_arn", role.Arn)
  d.Set("role_id", role.RoleId)
  d.Set("role_name", role.RoleName)
}

Copy link
Contributor Author

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 😆

resource.TestMatchResourceAttr(
"data.aws_iam_instance_profile.test",
"arn",
regexp.MustCompile("^arn:aws:iam::[0-9]{12}:instance-profile/testpath/"+profileName+"$"),
Copy link
Contributor

Choose a reason for hiding this comment

The 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 aws-cn/aws-us-gov. Easiest way is: ^arn:[^:]+:...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know. thanks 😄

@bflad bflad merged commit 7992cf3 into hashicorp:master Apr 23, 2018
@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service. labels Apr 23, 2018
@bflad bflad added this to the v1.16.0 milestone Apr 23, 2018
@loivis loivis deleted the 4080-ds-iam-instance-profile-export-role-name branch April 23, 2018 12:48
bflad added a commit that referenced this pull request Apr 23, 2018
@bflad
Copy link
Contributor

bflad commented Apr 25, 2018

This has been released in version 1.16.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 6, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_iam_instance_profile DataSource should return Role Name in addition to or instead of Role ID
2 participants