Search code examples
network-programminggoogle-cloud-platformdefaultgcloud

how to create gcp projects without default network using gcloud sdk


For terraform there is an option "auto_create_network = false" to skip creation of a default net within a new project.

Is there also an option/flag for gcloud sdk / gcloud projects create (e.g. --skip-default-network)? Or must we use org policy constraints/compute.skipDefaultNetworkCreation (https://cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints)?


Solution

  • Terraform's solution is to delete the default network promptly after creation:

    https://www.terraform.io/docs/providers/google/r/google_project.html#auto_create_network

    Therefore, you:

    • either use the org policy to never create it
    • or (you do what Terraform does and) gcloud compute networks delete it after creation:

    Example

    Please test this in a sacrificial project to ensure it meets your needs

    gcloud compute firewall-rules list \
    --project=${PROJECT} \
    --filter="network:/projects/${PROJECT}/global/networks/default" \
    --format="value(name)"  \
    | xargs gcloud compute firewall-rules delete \
    --project=${PROJECT} \
    --quiet
    
    gcloud compute networks delete default \
    --project=${PROJECT} \
    --quiet