# Create VPC Peering Connection between VPCs (Solution)

## Overview

* Labs are timed and cannot be paused. The timer starts when you click **Start Lab**.
    
* The included cloud terminal is preconfigured with the gcloud SDK.
    
* Use the terminal to execute commands and then click **Check my progress** to verify your work.
    

## Challenge scenario

As a network administrator, you have been assigned with the responsibility of connecting two Virtual Private Clouds (VPCs) workspace\_vpc and private\_vpc in your project. This peering connection will establish a direct and secure communication pathway between the resources residing in each VPC, allowing them to interact seamlessly with each other.

Your task is :

* Create Peering connection **workspace-vpc** with **private-vpc**
    
* Create Peering connection **private-vpc** with **workspace-vpc**
    

**Note:** To ssh into the vm instance, run the following command:

```apache
gcloud compute ssh INSTANCE_NAME --project=PROJECT_ID --zone=INSTANCE_ZONE
```

When asked if you want to continue, enter `Y`. When prompted for a passphrase, press **ENTER** for no passphrase, then **ENTER** again.

Click **Check my progress** to verify the objective.

---

## Solution of Lab

%[https://www.youtube.com/watch?v=iZwRujG_g2Y] 

```apache
curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/create-vpc-peering-connection-between-vpcs-solution/lab.sh
source lab.sh
```

**Script Alternative**

```apache

gcloud auth list

export ZONE=$(gcloud compute project-info describe --format="value(commonInstanceMetadata.items[google-compute-default-zone])")

export PROJECT_ID=$(gcloud config get-value project)

gcloud config set compute/zone "$ZONE"

gcloud compute networks create workspace-vpc --subnet-mode=custom

gcloud compute networks create private-vpc --subnet-mode=custom

gcloud compute networks peerings create workspace-to-private --network=workspace-vpc --peer-network=private-vpc --auto-create-routes

gcloud compute networks peerings create private-to-workspace --network=private-vpc --peer-network=workspace-vpc --auto-create-routes

gcloud compute ssh workspace-vm --project="$PROJECT_ID" --zone="$ZONE"
```
