summaryrefslogtreecommitdiffstats
path: root/ansible_collections/google/cloud/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/google/cloud/scripts')
-rwxr-xr-xansible_collections/google/cloud/scripts/bootstrap-project.sh15
-rwxr-xr-xansible_collections/google/cloud/scripts/cleanup-project.sh17
2 files changed, 24 insertions, 8 deletions
diff --git a/ansible_collections/google/cloud/scripts/bootstrap-project.sh b/ansible_collections/google/cloud/scripts/bootstrap-project.sh
index 8dd2b2d00..a28f42c79 100755
--- a/ansible_collections/google/cloud/scripts/bootstrap-project.sh
+++ b/ansible_collections/google/cloud/scripts/bootstrap-project.sh
@@ -40,12 +40,15 @@ for SERVICE in "${SERVICE_LIST[@]}"; do
gcloud services enable "$SERVICE" --project="$PROJECT_ID"
done
-for ROLE in "${REQUIRED_ROLE_LIST[@]}"; do
- echo "enabling role $ROLE..."
- gcloud projects add-iam-policy-binding "$PROJECT_ID" \
- --member="serviceAccount:$SERVICE_ACCOUNT_NAME" \
- --role="$ROLE"
-done
+if [ -n "$SERVICE_ACCOUNT_NAME" ]
+then
+ for ROLE in "${REQUIRED_ROLE_LIST[@]}"; do
+ echo "enabling role $ROLE..."
+ gcloud projects add-iam-policy-binding "$PROJECT_ID" \
+ --member="serviceAccount:$SERVICE_ACCOUNT_NAME" \
+ --role="$ROLE"
+ done
+fi
if ! gcloud app describe --project="$PROJECT_ID" > /dev/null; then
echo "creating appengine project..."
diff --git a/ansible_collections/google/cloud/scripts/cleanup-project.sh b/ansible_collections/google/cloud/scripts/cleanup-project.sh
index 4dd4ddb0a..b05a2f15f 100755
--- a/ansible_collections/google/cloud/scripts/cleanup-project.sh
+++ b/ansible_collections/google/cloud/scripts/cleanup-project.sh
@@ -40,8 +40,21 @@ cleanup_resource() {
extra_list_arg="$3"
extra_delete_arg="$4"
- for resource_id in $(gcloud "${resource_group}" "${resource}" list --project="${PROJECT_ID}" --format="csv[no-heading](name)" "${extra_list_arg}"); do
- gcloud "${resource_group}" "${resource}" delete "${resource_id}" --project="${PROJECT_ID}" -q "${extra_delete_arg}"
+ if [ -z "$extra_list_arg" ]
+ then
+ mapfile -t resources < <(gcloud "${resource_group}" "${resource}" list --project="${PROJECT_ID}" --format="csv[no-heading](name)")
+ else
+ mapfile -t resources < <(gcloud "${resource_group}" "${resource}" list --project="${PROJECT_ID}" --format="csv[no-heading](name)" "${extra_list_arg}")
+ fi
+
+ for resource_id in "${resources[@]}"
+ do
+ if [ -z "$extra_delete_arg" ]
+ then
+ gcloud "${resource_group}" "${resource}" delete "${resource_id}" --project="${PROJECT_ID}" -q
+ else
+ gcloud "${resource_group}" "${resource}" delete "${resource_id}" --project="${PROJECT_ID}" -q "${extra_delete_arg}"
+ fi
done
}