-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path036-admin-roles-import.sh
More file actions
executable file
·34 lines (27 loc) · 1.17 KB
/
036-admin-roles-import.sh
File metadata and controls
executable file
·34 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Resource: Role (Under Administration)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
DATA_DIR="$SCRIPT_DIR"/data/role
if [ ! -d $DATA_DIR ]; then
echo "Nothing to do without directory $DATA_DIR, please backup data first"
exit 0
fi
echo "************************************************************************"
echo "* Importing Customized Roles into TMC SM ..."
echo "************************************************************************"
role_type_json_template='{"type":{"kind":"Role","version":"v1alpha1","package":"vmware.tanzu.manage.v1alpha1.iam.role.Role"}}'
roleList=$(cat $DATA_DIR/roles.yaml | yq eval -o=json - | jq -c '.roles[]')
while IFS= read -r role; do
if [[ -z "$role" ]]; then
echo "No any customized role found"
fi
if [[ -n "$role" ]]; then
name=$(echo "$role" | jq -r '.fullName.name // ""')
echo "Create role $name"
echo "$role" | \
jq 'del(.fullName.orgId, .meta.parentReferences, .type)' | \
jq --argjson typeJson "$role_type_json_template" '. += $typeJson' | \
tanzu tmc iam role create --file -
fi
done <<< "$roleList"
echo "Imported Customized Roles into TMC SM ..."