Terraform configuration for setting up Google Cloud Shared VPC with separate production and development service projects.
- Host Project: Contains the shared VPC network
- Production Service Project: For production workloads
- Development Service Project: For development workloads
- Cloud Interconnect: Partner attachments for on-premises connectivity
- Google Cloud account with billing enabled
- Organization admin permissions
- Terraform >= 1.0 installed
gcloudCLI installed
git clone <repository-url>
cd gcp-sharedvpc-with-multiple-projects# Find your organization ID
gcloud organizations list
# Find your billing account
gcloud billing accounts listhost_project_id = "my-shared-vpc-host"
prod_service_project_id = "my-prod-service"
dev_service_project_id = "my-dev-service"
organization_id = "123456789012"
billing_account = "ABCDEF-123456-ABCDEF"
default_region = "us-central1"
secondary_region = "us-east1"# Initialize Terraform
terraform init
# Review the plan
terraform plan
# Apply the configuration
terraform apply| Environment | Subnet | Primary CIDR | Pods Range | Services Range |
|---|---|---|---|---|
| Production | prod-subnet-01 | 10.1.0.0/24 | 10.10.0.0/16 | 10.20.0.0/16 |
| Production | prod-subnet-02 | 10.2.0.0/24 | 10.11.0.0/16 | 10.21.0.0/16 |
| Development | dev-subnet-01 | 10.3.0.0/24 | 10.30.0.0/16 | 10.40.0.0/16 |
| Development | dev-subnet-02 | 10.4.0.0/24 | 10.31.0.0/16 | 10.41.0.0/16 |
main.tf- Main infrastructure resourcesvariables.tf- Input variablesoutputs.tf- Output valuesiam.tf- IAM permissionsproviders.tf- Provider configuration
# Check deployment status
terraform output
# Verify shared VPC
gcloud compute shared-vpc list-associated-projects <host-project-id>
# List subnets
gcloud compute networks subnets list --project=<host-project-id>
# Destroy everything
terraform destroyPermission Issues: Ensure you have Organization Admin or Project Creator + Billing Account User roles.
API Errors: APIs are automatically enabled, but check if billing is active.
Project ID Conflicts: All project IDs must be globally unique in GCP.
terraform destroyWarning: This will delete all projects and resources. Make sure you have backups of any important data.
For issues, check the official GCP documentation or Terraform Google Provider docs.
