Bird
Raised Fist0
GCPcloud~10 mins

Shared VPC concept in GCP - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Shared VPC concept
Host Project Created
Create VPC Network in Host
Attach Service Projects
Grant IAM Roles to Service Projects
Service Projects Use Shared VPC Resources
Resources Communicate Across Projects
End
This flow shows how a host project creates a VPC network, attaches service projects, grants permissions, and enables resource sharing across projects.
Execution Sample
GCP
1. Create host project
2. Create VPC network in host
3. Attach service project
4. Grant IAM roles
5. Deploy VM in service project using shared VPC
Steps to set up a Shared VPC where service projects use the host project's network.
Process Table
StepActionResultNotes
1Create host projectHost project createdThis project will own the VPC network
2Create VPC network in hostVPC network createdNetwork is isolated in host project
3Attach service projectService project linkedService project can use host's network
4Grant IAM rolesService project granted network user roleAllows service project to create resources in shared VPC
5Deploy VM in service projectVM uses shared VPC networkVM gets IP from host project's network
6VM communicates with other resourcesNetwork traffic flowsCross-project communication enabled
7EndSetup completeShared VPC is operational
💡 All steps completed; Shared VPC setup allows service projects to use host project's network resources.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Host ProjectNoneCreatedCreatedCreatedCreatedCreatedCreated
VPC NetworkNoneNoneCreatedCreatedCreatedCreatedCreated
Service ProjectNoneNoneNoneAttachedAttachedAttachedAttached
IAM RolesNoneNoneNoneNoneGrantedGrantedGranted
VM InstanceNoneNoneNoneNoneNoneDeployedDeployed
Key Moments - 3 Insights
Why can't service projects create their own VPC networks in a Shared VPC setup?
Service projects do not create their own VPCs; they use the host project's VPC network. This is shown in execution_table rows 2 and 3 where the VPC is created only in the host project and service projects are attached to it.
How does a VM in a service project get an IP address from the host project's network?
Because the service project has the 'network user' IAM role granted (row 4), it can deploy resources like VMs that use the host project's VPC network, as seen in row 5.
Can resources in service projects communicate with each other across projects?
Yes, once the Shared VPC is set up and VMs are deployed (rows 5 and 6), network traffic flows across projects using the shared network.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the service project linked to the host project?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Action' column for 'Attach service project' in execution_table.
According to variable_tracker, when is the VM instance deployed?
AAfter Step 3
BAfter Step 4
CAfter Step 5
DAt Start
💡 Hint
Look at the 'VM Instance' row and see when it changes from 'None' to 'Deployed'.
If the IAM roles were not granted, what would happen at Step 5 in execution_table?
AVM deployment would fail due to lack of permissions
BVM would deploy successfully
CService project would be detached
DHost project would be deleted
💡 Hint
Refer to Step 4 and Step 5 in execution_table about IAM roles and VM deployment.
Concept Snapshot
Shared VPC lets multiple projects use one VPC network.
Host project owns the network.
Service projects attach to host and get permissions.
Resources in service projects use host's network.
Enables centralized network management across projects.
Full Transcript
Shared VPC is a Google Cloud concept where one project, called the host project, owns a Virtual Private Cloud (VPC) network. Other projects, called service projects, attach to this host project to use its network resources. The setup involves creating the host project, creating a VPC network inside it, attaching service projects, granting them network user roles, and then deploying resources like virtual machines in the service projects that use the shared network. This allows resources across projects to communicate securely and centrally managed. The execution table shows each step from creating projects to deploying VMs, and the variable tracker shows how key variables change over time. Key moments clarify common confusions about network ownership, permissions, and communication. The visual quiz tests understanding of the setup steps and permissions.

Practice

(1/5)
1. What is the main purpose of a Shared VPC in Google Cloud Platform?
easy
A. To automatically back up virtual machines across projects
B. To create multiple isolated networks within a single project
C. To allow multiple projects to share the same Virtual Private Cloud network
D. To enable direct internet access for all projects

Solution

  1. Step 1: Understand Shared VPC concept

    Shared VPC allows multiple projects to connect to a common Virtual Private Cloud network managed by a host project.
  2. Step 2: Compare options

    To allow multiple projects to share the same Virtual Private Cloud network correctly describes this sharing of a VPC across projects. Other options describe unrelated features.
  3. Final Answer:

    To allow multiple projects to share the same Virtual Private Cloud network -> Option C
  4. Quick Check:

    Shared VPC = Shared network across projects [OK]
Hint: Shared VPC means sharing one network across projects [OK]
Common Mistakes:
  • Thinking Shared VPC creates isolated networks
  • Confusing Shared VPC with backups or internet access
  • Assuming Shared VPC is per project only
2. Which of the following is the correct way to enable Shared VPC on a host project using gcloud CLI?
easy
A. gcloud compute shared-vpc enable-host HOST_PROJECT_ID
B. gcloud projects add-iam-policy-binding HOST_PROJECT_ID --member=shared-vpc
C. gcloud compute shared-vpc enable --project=HOST_PROJECT_ID
D. gcloud compute networks create shared-vpc --project=HOST_PROJECT_ID

Solution

  1. Step 1: Identify correct gcloud command for enabling Shared VPC

    The command to enable Shared VPC on a host project is 'gcloud compute shared-vpc enable-host'.
  2. Step 2: Check options

    gcloud compute shared-vpc enable-host HOST_PROJECT_ID matches the correct syntax. Others are incorrect commands or unrelated.
  3. Final Answer:

    gcloud compute shared-vpc enable-host HOST_PROJECT_ID -> Option A
  4. Quick Check:

    Enable Shared VPC host with 'enable-host' command [OK]
Hint: Use 'enable-host' to activate Shared VPC on host project [OK]
Common Mistakes:
  • Using 'enable' instead of 'enable-host'
  • Confusing IAM binding with enabling Shared VPC
  • Trying to create a network instead of enabling Shared VPC
3. Given a Shared VPC setup where Project A is the host and Project B is a service project, what happens if a VM in Project B tries to use a subnet from Project A's Shared VPC?
medium
A. The VM can use the subnet and communicate within the Shared VPC network
B. The VM creation fails because subnets cannot be shared
C. The VM uses a default subnet from Project B instead
D. The VM gets an external IP automatically

Solution

  1. Step 1: Understand Shared VPC subnet usage

    In Shared VPC, service projects can create resources using subnets from the host project's VPC.
  2. Step 2: Analyze VM subnet assignment

    VM in Project B can use Project A's subnet and communicate within the shared network.
  3. Final Answer:

    The VM can use the subnet and communicate within the Shared VPC network -> Option A
  4. Quick Check:

    Shared VPC allows subnet sharing for VM networking [OK]
Hint: Service projects use host subnets for VM networking [OK]
Common Mistakes:
  • Assuming subnets cannot be shared
  • Thinking VM defaults to service project subnet
  • Confusing external IP assignment with subnet usage
4. You configured a Shared VPC but a service project cannot create VM instances using the host project's subnets. What is the most likely cause?
medium
A. The host project does not have any subnets created
B. The VM instance name is invalid
C. The service project is not linked to the host project
D. The service project lacks the 'compute.networkUser' role on the host project

Solution

  1. Step 1: Check permissions for service project

    Service projects need 'compute.networkUser' role on the host project to use its subnets.
  2. Step 2: Verify linkage and subnet existence

    While linkage and subnets are important, lack of permission is the most common cause blocking VM creation.
  3. Final Answer:

    The service project lacks the 'compute.networkUser' role on the host project -> Option D
  4. Quick Check:

    Missing networkUser role blocks subnet use [OK]
Hint: Check 'compute.networkUser' role for service project [OK]
Common Mistakes:
  • Ignoring IAM roles and permissions
  • Assuming linkage alone is enough
  • Blaming VM name instead of network access
5. You want to design a secure environment where multiple teams have their own projects but share a common network with strict firewall rules managed centrally. How does using Shared VPC help achieve this?
hard
A. It requires each team to create their own VPC and manage firewall rules independently
B. It centralizes network management in one host project while teams use service projects for resources
C. It automatically applies firewall rules per project without central control
D. It isolates each team's network completely with no sharing

Solution

  1. Step 1: Understand Shared VPC central management

    Shared VPC lets you manage network and firewall rules centrally in a host project.
  2. Step 2: Analyze team project usage

    Teams use service projects to create resources but rely on the shared network and firewall rules from the host project.
  3. Step 3: Compare options

    It centralizes network management in one host project while teams use service projects for resources correctly describes this central control with resource separation. Other options describe isolation or decentralized management.
  4. Final Answer:

    It centralizes network management in one host project while teams use service projects for resources -> Option B
  5. Quick Check:

    Shared VPC centralizes network and firewall control [OK]
Hint: Shared VPC centralizes network, teams use separate projects [OK]
Common Mistakes:
  • Thinking Shared VPC isolates networks fully
  • Assuming firewall rules are per project automatically
  • Believing teams manage their own VPCs independently