Skip to content

Instantly share code, notes, and snippets.

@KoeSystems
Last active November 17, 2020 19:41
Show Gist options
  • Save KoeSystems/218ccd52987106f27d12a9b72f8f10a6 to your computer and use it in GitHub Desktop.
Save KoeSystems/218ccd52987106f27d12a9b72f8f10a6 to your computer and use it in GitHub Desktop.
Delete default VPC network in GCP with Terraform
###############################################################################
# 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