Hi,
I'd like to create a report on IAM policies as a CSV file. I'm listing the organization, plus resources, members and roles with the following command:
gcloud asset search-all-iam-policies --scope=organizations/012345678901 --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)'
In the output, the first column shows the organization ID.
Is it possible to show the organization displayName instead of the ID?
Thanks
Solved! Go to Solution.
Not directly in that single gcloud command because it does not return that field, but you can look up the displayName using something like:
gcloud organizations list --filter=012345678901 --format="value(displayName)"
So if you're in a bash shell you could combine them together with sed to do something like this:
DISPLAYNAME=$(gcloud organizations list --filter=012345678901 --format="value(displayName)"); gcloud asset search-all-iam-policies --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)' | sed "s/^012345678901/$DISPLAYNAME/"
That should be all one line 🙂
Hope that helps.
Not directly in that single gcloud command because it does not return that field, but you can look up the displayName using something like:
gcloud organizations list --filter=012345678901 --format="value(displayName)"
So if you're in a bash shell you could combine them together with sed to do something like this:
DISPLAYNAME=$(gcloud organizations list --filter=012345678901 --format="value(displayName)"); gcloud asset search-all-iam-policies --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)' | sed "s/^012345678901/$DISPLAYNAME/"
That should be all one line 🙂
Hope that helps.
Perfect, this is very helpful, thanks!