Last active
November 17, 2020 19:41
-
-
Save KoeSystems/218ccd52987106f27d12a9b72f8f10a6 to your computer and use it in GitHub Desktop.
Delete default VPC network in GCP with Terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# Delete Default VPCs | |
############################################################################### | |
resource null_resource delete_default_vpc { | |
triggers = { | |
always = timestamp() | |
} | |
provisioner "local-exec" { | |
command = <<-EOT | |
FW_RULES_ID=$(gcloud compute firewall-rules list --filter="network~'default'" --format=json | jq .[].name ) | |
if [ "$${FW_RULES_ID}" == "" ]; then | |
echo "No default firewall rules found" | |
else | |
gcloud compute firewall-rules delete $${FW_RULES_ID} --quiet | |
echo "Default VPC deleted" | |
fi | |
VPN_ID=$(gcloud compute networks list --filter="name~'default'" --format="json" | jq .[0].name | xargs) | |
if [ "$${VPN_ID}" == "" ]; then | |
echo "No default VPC found" | |
else | |
gcloud compute networks delete $${VPN_ID} --quiet | |
echo "Default VPC deleted" | |
fi | |
EOT | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment