Back to Terraform

Google Networking: VPCs, Shared VPC, Firewall and Private Service Paths

November 6, 2026 Wasil Zafar 23 min read

Model project-aware connectivity and private access without translating AWS concepts mechanically

Table of Contents

  1. Draw Network and Subnet Scope Across Projects
  2. Design Firewall and Routing Ownership Explicitly
  3. Choose Cloud NAT, Private Google Access and Service Connectivity
  4. Model Shared VPC Host and Service Project Permissions
  5. Verify DNS, Egress and a Denied Private Path

Draw Network and Subnet Scope Across Projects

A Google VPC is a global routing domain; its subnets are regional. The network object spans every region you enable, a subnet belongs to exactly one region, and a VM network interface belongs to one zone. That order — global network, regional subnet, zonal resource — is the first thing to unlearn from a regional VNet or a regional AWS VPC.

A subnet is both an address range and a placement rule. Two VMs in different zones of the same region can share one subnet and talk over it; a VM in another region needs a different subnet. There is no per-zone subnet and no implicit subnet in a region you never created.

The routing table is a property of the network, not the subnet. Every subnet route is visible across the whole VPC, so two VMs in different regions reach each other without peering or a route you write. A standalone VPC already gives you that reach; Shared VPC changes who owns it, not how far it goes.

Follow one packet out of a VM. The source NIC evaluates the egress rule set, the network routing table selects a subnet or custom route, and the destination NIC evaluates ingress before the connection is delivered. There is no hop-by-hop firewall appliance in the path; both decisions happen at the endpoints.

Subnet routes are evaluated before custom static and dynamic routes. If a destination falls inside any subnet in the VPC, Google delivers by that subnet route and stops; policy-based routes are the exception because they run earlier. A custom static route is consulted only for destinations outside every subnet, then by most specific prefix, then by priority.

A project is an ownership boundary, not a network boundary. A standalone VPC keeps network and workloads in one project; Shared VPC lets a host project own the network while service projects attach workloads. Decide from who must write routes and firewall rules, not from how many regions the packets cross.

Choose standalone when one team owns both layers. It has fewer IAM edges, one state file, and no attachment to break. Choose Shared VPC when network administration is central and workload teams must not change routes, firewalls or address ranges; the cost is a second project boundary and a role model that has to be granted deliberately.

Address planning is the decision that is hardest to reverse. Subnets cannot overlap inside one VPC, peering and private service access require non-overlapping ranges, and a range you hand to a managed service is not available for a subnet. Reserve per environment and leave room for the private service ranges before the first workload lands.

Draw Network and Subnet Scope Across Projects
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    ORG["Organization
host and service projects"] --> HOST["Host project
owns network and policy"] ORG --> SVC["Service project
owns workloads"] HOST --> NET["Global VPC
one routing table"] NET --> R1["Regional subnet
us-central1 10.20.0.0/24"] NET --> R2["Regional subnet
europe-west1 10.20.1.0/24"] R1 --> Z1["Zonal VM
us-central1-a"] R1 --> Z2["Zonal VM
us-central1-b"] R2 --> Z3["Zonal VM
europe-west1-b"] SVC -.->|"networkUser on one subnet"| R1 classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class ORG,NET primary; class HOST,Z1,Z2,Z3 secondary; class SVC warn; class R1,R2 ok;

Figure 1 separates the scopes that are often drawn as one box. The organization and the project are ownership scopes, the VPC is a routing scope, and the subnet is the only object tied to a region. The dotted edge is an IAM grant, not a network link, which is why the service project can use the subnet without owning it.

Network, subnet and project scopes in Google Cloud An organization boundary contains a host project that owns a global VPC and two regional subnets, and a service project that consumes one subnet through an IAM grant. Zonal VMs sit inside the regional subnets. One network, three scopes that do not line up ORGANIZATION host and service projects share it Host project Owns the VPC, subnets, routes and firewall policy Network Admin and Security Admin compute.xpnAdmin at the org Service project Owns VMs, GKE nodes and service accounts No route, NAT or firewall write compute.networkUser on one subnet IAM grant, not a route Global VPC network one routing table for every enabled region REGION us-central1 Subnet 10.20.0.0/24 regional address range VM us-central1-a VM us-central1-b A subnet spans zones, not regions. Two zones share one range and one route. REGION europe-west1 Subnet 10.20.1.0/24 a different regional range VM europe-west1-b Same VPC, different region The subnet route is in the network table, so no peering.

Figure 2 draws the same network at each scope. The host project owns the global network and the two regional subnets; the service project owns only the VMs that consume one of them. Nothing in the packet path crosses a project boundary, which is why Shared VPC can be invisible to the application.

Design Firewall and Routing Ownership Explicitly

A firewall rule is enforced at the NIC, and it is stateful. Google evaluates the rule set when a connection is initiated and admits the return packets of an established connection. You do not write a return rule, and rule position in the file means nothing; priority decides.

A VPC firewall rule is network-scoped and targets by tag or service account. Priorities run from 0 to 65535, the first match wins, and the implied rules deny ingress and allow egress at 65535. A target tag is a string that anyone with instance-edit permission can add, so a tag-based allow is only as strict as tag-write access; a target service account requires permission to attach that identity.

A firewall policy is a different resource with a different owner. Hierarchical policies attach to an organization or folder and cover many VPCs; network policies attach to one VPC and can be global or regional. Rules live inside the policy, and goto_next lets a layer abstain instead of deciding.

The default order evaluates VPC rules before network policies. Google runs hierarchical policies, then regional system policies, then VPC firewall rules, then global network policies, then regional network policies, then the implied action. A network policy deny written to override a VPC allow never runs, because the VPC allow already ended evaluation; that is the conflict that makes two teams each believe the other rule is broken.

Two VPC rules at the same priority resolve to deny. If an allow and a deny match at the same priority, Google enforces the deny and ignores the allow. Treat equal priorities as a review defect, not a tie-breaker you can reason about later.

Routing ownership splits just as easily. Subnet routes are system-managed, but custom static routes, policy-based routes, Cloud Router sessions and NAT are network-level objects. A principal who can create a route can redirect another team's traffic, so route write access belongs with the network owner, not the application owner.

Name one owner for the whole decision. In a Shared VPC, the Security Admin owns the policy attached to the network and its VPC rules, while the Network Admin owns subnets, routes, NAT and peering. Service teams get roles/compute.networkUser on named subnets and no firewall write. When two teams can write the same layer, the effective policy is whichever apply ran last.

This article targets Terraform 1.17.1 and hashicorp/google 8.10.0. In that provider a VPC rule is still a firewall resource on the network, while policy rules use their own policy and association resources. Managing one flow with both a policy rule and a VPC rule is a design conflict, not something Terraform will merge for you.

Policy rules also have a scope-specific resource. The hierarchical rule resource belongs with an organization or folder policy, and the network policy rule resource belongs with a VPC policy. A rule created against the wrong policy parent applies nowhere, and the plan will look correct.

Design Firewall and Routing Ownership Explicitly
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    P["New connection
ingress or egress"] --> H{"Hierarchical policy
organization then folder"} H -- "allow or deny" --> S1["First match wins
lower layers never run"] H -- "no match or goto_next" --> SYS["Regional system policy
managed by Google"] SYS -- "allow or deny" --> S2["Decision is final"] SYS -- "goto_next" --> VPC{"VPC firewall rules
default enforcement order"} VPC -- "allow" --> OK["Connection admitted
network policy is not consulted"] VPC -- "deny" --> D1["Dropped at the VPC layer"] VPC -- "no match" --> G{"Global network policy"} G -- "allow or deny" --> S3["Final decision
only when VPC had no match"] G -- "no match or goto_next" --> R{"Regional network policy"} R -- "allow or deny" --> S4["Decision is final"] R -- "no match" --> IMP["Implied action
ingress deny, egress allow"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class H,SYS,VPC,G,R primary; class S1,S2,S3,S4 secondary; class OK ok; class D1 danger; class IMP warn;

Figure 3 follows one new connection through every layer. The red exit is the one that surprises people: once a VPC rule allows, the network policy below it is never consulted, so a later deny is not an override. The amber exit is also a decision; an implied deny is policy, not the absence of policy.

Choose Cloud NAT, Private Google Access and Service Connectivity

Egress without an external address needs a path, and the paths are not interchangeable. Cloud NAT gives a private VM the internet, Private Google Access gives it Google APIs, and Private Service Connect or private service access gives it a specific private service. Installing one does not install the others.

Cloud NAT is regional and attached to a Cloud Router. It translates the source address for the subnets you name, accepts no inbound connections, and has no effect on traffic that already has a private destination. A second region needs its own NAT gateway, and a NAT gateway is not a firewall; the egress rule still has to allow the connection.

Private Google Access is a subnet setting, not a route. With it on, a VM that has only an internal address can reach the private VIPs for Google APIs; with it off, the same VM has no path even though the VPC has a default route. The client still needs DNS that returns the private VIP rather than the public address.

PSC for Google APIs reserves an address in your own VPC. You reserve a global internal address with purpose PRIVATE_SERVICE_CONNECT, then point a global forwarding rule at the all-apis bundle. Traffic stays on Google's network, but the endpoint is not reachable from a peered VPC, and an internal-only VM still needs Private Google Access enabled on its subnet.

PSC for a producer service is a forwarding rule to a service attachment. The producer publishes the attachment, the consumer creates a forwarding rule in its own subnet, and the consumer address comes from its own range. That is why PSC tolerates overlapping CIDRs where VPC peering cannot.

Private service access is the older peering contract. You allocate a global range with purpose VPC_PEERING, connect it to the service networking API, and a managed service such as Cloud SQL takes an address from it. The range must not overlap anything you route, and the peering does not transitively extend to a third network.

DNS decides which path the application actually takes. A PSC endpoint with no record is a service nobody calls, and a PGA-enabled subnet with public DNS answers never reaches the private VIP. Match the record to the path: endpoint address for PSC, private VIP for PGA, and the service's own name for private service access.

Choose by contract, not by diagram. Need a private Google API and no CIDR coupling: PSC. Need a managed database on a private range and accept peering: private service access. Need outbound internet from an internal VM: NAT. Need only Google APIs and no custom address: Private Google Access plus the right private DNS records.

Model Shared VPC Host and Service Project Permissions

Shared VPC is an IAM attachment between two projects in one organization. The host project owns the network; a service project attaches to exactly one host and cannot itself be a host. The attachment is project-level, so it changes what every workload in that project may use.

Enabling the host and attaching a service project are separate resources. google_compute_shared_vpc_host_project marks the host, and google_compute_shared_vpc_service_project creates the attachment. Neither moves an existing VM: a resource created on a standalone network keeps that network, and using the shared network means recreating it.

The Shared VPC Admin role is organization or folder scoped. It combines roles/compute.xpnAdmin with roles/resourcemanager.projectIamAdmin, because enabling a host and granting subnet access are both IAM writes. A project owner cannot bootstrap Shared VPC alone.

Network Admin and Security Admin are deliberately different jobs. The Network Admin role covers subnets, routes, NAT and peering but not firewall rules; the Security Admin role covers firewall rules and certificates. Collapsing both into one principal is convenient and removes the separation the model exists to provide.

A service project admin gets networkUser on named subnets. roles/compute.networkUser at the host-project level grants every subnet in every network, including ones added later; at the subnet level it grants only the range the workload needs. Pair it with instance administration in the service project so the team can create VMs but not change routing.

Some services need an additional host-project grant. The GKE service agent needs roles/container.hostServiceAgentUser on the host project, and the node service account needs network use on the subnet. Without both, the cluster can be created while nodes fail to join.

Organization policy narrows the attachment, not the data path. Constraints can limit which host projects a service project may attach to and which subnets it may use; they do not retrofit existing VMs, and PSC forwarding rules are exempt from the subnet constraint. A security review that assumes the constraint covers every private path is reviewing the wrong object.

Billing follows the workload even when the network is shared. Instance and outbound traffic charges land in the service project, while VPN and Interconnect charges land in the project that owns the gateway or VLAN attachment. That asymmetry is often the real reason to split projects, long before network scale matters.

ResponsibilityOwnerRole or resourceFailure when misplaced
Enable the hostShared VPC Adminroles/compute.xpnAdminAttachment cannot be created
Attach a service projectShared VPC Admingoogle_compute_shared_vpc_service_projectWorkload has no shared subnet
Use one subnetService teamroles/compute.networkUser on the subnetProject-level grant exposes every subnet
Create a VMService project teamroles/compute.instanceAdmin.v1Team can build but not change the network
Write firewall rulesHost Security Adminroles/compute.securityAdminTwo owners produce an unreviewable rule set
Write routes and NATHost Network Adminroles/compute.networkAdminA service team can redirect another team's traffic
Publish the shared private zoneHost network teamgoogle_dns_managed_zoneService projects resolve the public name

Table 1 assigns each decision to one project and one role. The rows that fail most often are the subnet grant, which silently widens to the whole host when granted at project level, and the firewall row, where a service team's convenience rule defeats the host policy.

Shared VPC subnet grant before and after, with the project-level failure path On the left a service project is attached to a host project but cannot create an instance because it lacks network user on the subnet. On the right the service project has network user on one subnet and creates a VM there. An amber band shows that a project-level grant would expose every subnet in the host. Grant the subnet, not the project BEFORE · NO NETWORK USER Service project VM to create Host project VPC and subnet Subnet 10.20.0.0/24 exists and is shared Instance create stops at the subnet The service project is attached, but it has no network user grant on the subnet. The network is visible, the range is not usable. AFTER · SUBNET-LEVEL NETWORK USER Service project VM created Host project VPC and subnet Subnet 10.20.0.0/24 IP assigned from here One subnet, one grant, one address range The instance gets an address from the shared range. The team still cannot create a route, a NAT gateway or a firewall rule in the host project. FAILURE PATH · PROJECT-LEVEL NETWORK USER The same grant at the host-project level makes every subnet in every network usable, including subnets added later. The workload still works, so nothing fails review. The blast radius is the whole host project, and the plan shows no difference. Grant at the subnet. Add a new subnet when a new team needs one.

Figure 4 shows the same request before and after the subnet grant. On the left the service project can see the host network but cannot create an instance in it; on the right one subnet is usable. The amber band is the failure mode that looks like success: a project-level grant makes every subnet usable, including the ones added next quarter.

Verify DNS, Egress and a Denied Private Path

The Terraform runner is usually outside the network it builds. A laptop or hosted CI agent reaches the control plane over the internet, so it can apply a private endpoint it cannot use. Test from a VM or pod in the workload subnet, with the same route table, firewall targets and DNS resolver as the application.

Control-plane success and data-plane success are different claims. The provider creates the forwarding rule or database through the API; the client still needs a route, an allow rule and a name. A clean apply followed by a timing-out request is a common first result, not a contradiction.

Resolve before you connect. A query from the runner shows which path DNS chose: a public answer means the private zone is missing, unlinked or shadowed. Then connect to the name rather than the address, so the test covers the record the application will actually use.

Prove one allowed and one denied path. The allowed path should show a private destination and a completed request; the denied path should fail fast with a refusal or leave a firewall log entry, not hang. A hang usually means routing or an implied drop, while a refusal means the packet arrived and a rule or the service said no.

Read effective rules, not the ones you wrote. The effective firewall list on the VM interface includes hierarchical, policy and VPC layers in evaluation order, and the route list on the NIC shows what the network selected. A policy document is not evidence that the path exists.

Break DNS last and restore it first. Removing the private zone is the cleanest proof that the name steers traffic, and the fastest way to strand your own session. Record the answer before and after, then restore the zone before any other test.

Destroy in dependency order. PSC forwarding rules and addresses, private service connections, NAT gateways and DNS zones all have to come out before the network, and several of them keep billing while orphaned. Check the state list before the console, because the state names the owner.

Lab

Verify DNS, Egress and a Denied Private Path

Status: design-only. One host project, one service project, one PSC endpoint for Google APIs and one runner VM in the workload subnet; the trace is a design, not a claim that it ran.

Prerequisites. Terraform 1.17.1 and hashicorp/google 8.10.0, a host project with the Compute, DNS and Service Directory APIs enabled, a service project attached to it, and a runner VM without an external address that you reach through IAP.

Steps.

  1. Apply the host network: global VPC, workload subnet with Private Google Access on, and a deny-by-default ingress rule with logging enabled.
  2. Attach the service project and grant roles/compute.networkUser on the workload subnet only.
  3. Reserve the PSC global address and create the global forwarding rule for the all-apis bundle.
  4. Create a private DNS zone for googleapis.com, an A record at the apex pointing at the endpoint, and a wildcard CNAME.
  5. Create the runner in the workload subnet, add an IAP SSH allow for 35.235.240.0/20, and connect through IAP.
  6. Resolve a Google API name from the runner and record the answer.
  7. Call the endpoint, then call a VM in another subnet on a port the firewall does not allow.
  8. Remove the private zone, resolve again, restore it, and destroy the stack.
CheckMethodPass conditionFailure signal
DNSdig +short storage.googleapis.comAnswer is the endpoint addressPublic address means the zone is not authoritative
PSC pathcurl http://ENDPOINT_IP/generate_204HTTP 204 from the endpointTimeout means no route or no egress allow
Allowed namecurl -v the API name from the runnerConnected to the endpoint addressPublic destination means DNS won
Denied portcurl the peer VM on an unallowed portTimeout plus a firewall deny logAny response means the packet arrived
No NATcurl a public site from the runnerFailure, because no NAT existsSuccess means an unintended egress path
DNS proofRemove the private zone and resolvePublic answer returnsStill private means another zone answers

Expected observation. The runner resolves the API name to the endpoint address, the endpoint returns 204, the peer VM on the unallowed port times out with a deny entry, and the public site fails because no NAT exists. Removing the private zone returns the public answer, and restoring it returns the private one.

Failure check. The lab fails if the name resolves publicly with the zone linked, if the allowed call reaches a public address, if the denied port succeeds, if the no-NAT call succeeds, or if a plan is treated as proof of connectivity.

Cost and cleanup. One runner VM, one reserved global address, one forwarding rule, one DNS zone and its records, plus the host network. Delete the forwarding rule before the address, remove the DNS zone last, and confirm no reserved address remains.

Evidence to keep. The resolved answers before and after, the endpoint response code, one firewall deny log, and the state list after destroy.

Next in the Series

In Compute Engine: Instance Templates, Managed Groups and Load Balancing, we'll explore Release VM-based capacity through stable templates and independently verified health.