如何使用 gcloud sdk 在没有默认网络的情况下创建 gcp 项目

how to create gcp projects without default network using gcloud sdk

对于 terraform,有一个选项 "auto_create_network = false" 可以跳过在新项目中创建默认网络。

gcloud sdk / gcloud 项目创建是否也有 option/flag(例如 --skip-default-network)?或者我们必须使用组织政策 constraints/compute.skipDefaultNetworkCreation (https://cloud.google.com/resource-manager/docs/organization-policy/org-policy-constraints)?

Terraform 的解决方案是创建后立即删除默认网络:

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

因此,您:

  • 要么使用组织策略从不创建它
  • 或者(你做 Terraform 做的事然后)gcloud compute networks delete 创建后:

例子

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