-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Create data source for aws iam roles #18585
Conversation
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.
Welcome @jlamande 👋
It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.
Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.
Thanks again, and welcome to the community! 😃
ba859b5
to
e0f1757
Compare
Awesome work! Just commenting to add a link to a related issue : #14470 |
Hi @anGie44 |
Hi @anGie44, |
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.
Hi @jlamande , thank you for this PR! It's off to a great start. A couple comments to address given we'll want to support a different argument in place of filter
(as it's not natively supported by the API method), but things should fall into place once that is addressed. I've suggested the use of name_regex
but if you feel name_prefix
or another alternative may be better suited for this data source, feel free to discuss here!
This is potentially a follow up feature request but it might be useful to also return the ARNs wtih the path stripped. Or at least documentation should show how to get at the ARN without the path in it. EKS role mapping against AWS SSO roles for some reason requires the path to be removed from the ARN of the role. This is documented in https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html and https://docs.aws.amazon.com/eks/latest/userguide/troubleshooting_iam.html#security-iam-troubleshoot-ConfigMap |
This PR will be incredibly useful and provides a workaround for #20552, thank you! Any idea on when this may get released? |
a13129c
to
f7c17b8
Compare
f7c17b8
to
c4a413c
Compare
### Role ARNs with paths removed | ||
|
||
For services like Amazon EKS that do not permit a path in the role ARN when used in a cluster's configuration map | ||
|
||
```terraform | ||
data "aws_iam_roles" "roles" { | ||
path_prefix = "/aws-reserved/sso.amazonaws.com/" | ||
} | ||
|
||
output "arns" { | ||
value = [ | ||
for parts in [for arn in data.aws_iam_roles.roles.arns : split("/", arn)] : | ||
format("%s/%s", parts[0], element(parts, length(parts) - 1)) | ||
] | ||
} | ||
``` |
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.
@tomelliff thanks for pointing out this type of usage! hope this helps :)
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.
Thanks again @jlamande for introducing this new data source 🎉 To help this get into an upcoming release, I've committed the requested changes.
Output of acceptance tests (commercial):
--- PASS: TestAccAWSIAMRolesDataSource_nonExistentPathPrefix (11.37s)
--- PASS: TestAccAWSIAMRolesDataSource_nameRegex (19.79s)
--- PASS: TestAccAWSIAMRolesDataSource_basic (20.72s)
--- PASS: TestAccAWSIAMRolesDataSource_pathPrefix (21.56s)
--- PASS: TestAccAWSIAMRolesDataSource_nameRegexAndPathPrefix (31.89s)
Hi @anGie44 |
No worries @jlamande ! |
This functionality has been released in v3.55.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
The purpose of this new data source is to provide a way get ARNs and Names of IAM Roles that are created outside of the current Terraform state.
E.g., in an AWS SSO powered environment, IAM Roles are automatically provisioned by AWS SSO in the different AWS accounts of the organization and their names is only following a pattern. The exact name is unpredictable because it contains a random/hash number.
When provisioning resources based on these roles (as Kubernetes aws-auth map) this data source is a must-have.
Community Note
Closes #14470
Closes #14173
Output from acceptance testing: