Issue
I would like realized inventory of GCP Org policies which are SET in my organization top folders, so I want to use bash script in my cloud shell terminal.
Code below works but I want use folder "DisplayName" and not folder ID.
DisplayName can be retrieve with this cmd gcloud beta resource-manager folders list --organization=XXXXX--format=value"(ID, DISPLAY_NAME)
but it is difficult to organize result later in one table
#!/bin/bash
for folder in $(gcloud beta resource-manager folders list --organization=XXXXX --format="value(ID)")
do
echo $folder
gcloud beta resource-manager org-policies list --folder=$folder
done
Solution
I don't have access to either organization
or folder
but, the following should work.
The trick is to use --format=csv[no-heading]
to provide a more readily 'parseable` values:
#!/bin/bash
ORGANIZATION="..."
PAIRS=$(\
gcloud beta resource-manager folders list \
--organization=${ORGANIZATION} \
--format="csv[no-heading](ID,displayName)")
for PAIR in ${PAIRS}
do
IFS=, read ID DISPLAY_NAME <<< ${PAIR}
echo ${DISPLAY_NAME}
gcloud beta resource-manager org-policies list \
--folder=${ID}
done
Answered By - DazWilkin Answer Checked By - Katrina (WPSolving Volunteer)