Skip to content

Instantly share code, notes, and snippets.

@pydevops
Last active July 1, 2021 17:07
Show Gist options
  • Save pydevops/879f22eb929466dfe79d7bb7e1272e53 to your computer and use it in GitHub Desktop.
Save pydevops/879f22eb929466dfe79d7bb7e1272e53 to your computer and use it in GitHub Desktop.
bash dump basic gcp networks
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# For one project only
# Please make sure to run `gcloud config set project <project_id> first`
command -v gcloud >/dev/null 2>&1 || \
{ echo >&2 "I require gcloud but it's not installed. Aborting.";exit 1; }
PROJECT_ID=$(gcloud config list project --format 'value(core.project)')
if [ -z "${PROJECT_ID}" ]
then echo >&2 "I require default project is set but it's not. Aborting."; exit 1;
fi
OUT=$PROJECT_ID.txt
cat /dev/null > $OUT
echo "**networks**" >> $OUT
gcloud compute networks list >> $OUT
echo "**subnets**" >> $OUT
gcloud compute networks subnets list --sort-by=NETWORK >> $OUT
echo "**routes**" >> $OUT
gcloud compute routes list --sort-by=NETWORK >> $OUT
echo "**firewall-rules**" >> $OUT
gcloud compute firewall-rules list --sort-by=NETWORK >> $OUT
```
echo "##Please send the content of $OUT to us, thanks!##"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment