|
| 1 | +--- |
| 2 | +# generated by https://github.com/hashicorp/terraform-plugin-docs |
| 3 | +page_title: "stacklet_role_assignments Data Source - terraform-provider-stacklet" |
| 4 | +subcategory: "" |
| 5 | +description: |- |
| 6 | + Retrieve role assignments for a specific target. This data source allows you to query which principals (users or SSO groups) have been granted roles on a particular target (system, account group, policy collection, or repository). |
| 7 | +--- |
| 8 | + |
| 9 | +# stacklet_role_assignments (Data Source) |
| 10 | + |
| 11 | +Retrieve role assignments for a specific target. This data source allows you to query which principals (users or SSO groups) have been granted roles on a particular target (system, account group, policy collection, or repository). |
| 12 | + |
| 13 | +## Example Usage |
| 14 | + |
| 15 | +```terraform |
| 16 | +# Query all system-level role assignments |
| 17 | +data "stacklet_role_assignments" "system_access" { |
| 18 | + target = "system:all" |
| 19 | +} |
| 20 | +
|
| 21 | +# Query role assignments for a specific account group |
| 22 | +data "stacklet_role_assignments" "production_acl" { |
| 23 | + target = "account-group:00000000-0000-0000-0000-000000000001" |
| 24 | +} |
| 25 | +
|
| 26 | +# Query role assignments for a policy collection |
| 27 | +data "stacklet_role_assignments" "security_policies_access" { |
| 28 | + target = "policy-collection:00000000-0000-0000-0000-000000000002" |
| 29 | +} |
| 30 | +
|
| 31 | +# Query role assignments for a repository |
| 32 | +data "stacklet_role_assignments" "repo_access" { |
| 33 | + target = "repository:00000000-0000-0000-0000-000000000003" |
| 34 | +} |
| 35 | +
|
| 36 | +# Output all system administrators |
| 37 | +output "system_admins" { |
| 38 | + description = "All principals with system-level access" |
| 39 | + value = [ |
| 40 | + for assignment in data.stacklet_role_assignments.system_access.assignments : |
| 41 | + { |
| 42 | + role = assignment.role_name |
| 43 | + principal = assignment.principal |
| 44 | + } |
| 45 | + ] |
| 46 | +} |
| 47 | +
|
| 48 | +# Output production account group access control list |
| 49 | +output "production_access_summary" { |
| 50 | + description = "Summary of who has access to the production account group" |
| 51 | + value = { |
| 52 | + total_assignments = length(data.stacklet_role_assignments.production_acl.assignments) |
| 53 | + assignments = data.stacklet_role_assignments.production_acl.assignments |
| 54 | + } |
| 55 | +} |
| 56 | +
|
| 57 | +# Check if specific user has access |
| 58 | +locals { |
| 59 | + user_id_to_check = 123 |
| 60 | +
|
| 61 | + user_has_production_access = anytrue([ |
| 62 | + for assignment in data.stacklet_role_assignments.production_acl.assignments : |
| 63 | + assignment.principal.type == "user" && assignment.principal.id == local.user_id_to_check |
| 64 | + ]) |
| 65 | +} |
| 66 | +
|
| 67 | +output "user_has_access" { |
| 68 | + description = "Whether user 123 has any role on the production account group" |
| 69 | + value = local.user_has_production_access |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +<!-- schema generated by tfplugindocs --> |
| 74 | +## Schema |
| 75 | + |
| 76 | +### Required |
| 77 | + |
| 78 | +- `target` (String) An opaque target identifier to query role assignments for. Use the 'role_assignment_target' attribute from resource outputs. |
| 79 | + |
| 80 | +### Read-Only |
| 81 | + |
| 82 | +- `assignments` (Attributes List) The list of role assignments for the target. (see [below for nested schema](#nestedatt--assignments)) |
| 83 | + |
| 84 | +<a id="nestedatt--assignments"></a> |
| 85 | +### Nested Schema for `assignments` |
| 86 | + |
| 87 | +Read-Only: |
| 88 | + |
| 89 | +- `id` (String) The unique identifier of the role assignment. |
| 90 | +- `principal` (String) An opaque principal identifier. |
| 91 | +- `role_name` (String) The name of the role assigned. |
| 92 | +- `target` (String) An opaque target identifier. |
0 commit comments