# Assign External IP to VM Instance using gcloud (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

You are a system administrator for a company that uses Google Cloud to host its applications. You have an existing compute instance without an external IP in the default VPC network.

Your task is to assign static external IP address to your virtual machine (VM) instances.

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

Create a static external IP address

---

## Solution of Lab

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

```apache
curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/assign-external-ip-to-vm-instance-using-gcloud-solution/lab.sh
source lab.sh
```

**Script Alternative**

```apache
export VM_NAME=$(gcloud compute instances list --format='value(name)' --limit=1) && export ZONE=$(gcloud compute instances list --format='value(zone)' --limit=1) && export REGION=${ZONE%-*}
gcloud compute addresses create lab-static-ip --region=$REGION
export IP_ADDRESS=$(gcloud compute addresses describe lab-static-ip --region=$REGION --format='get(address)') && gcloud compute instances add-access-config $VM_NAME --zone=$ZONE --address=$IP_ADDRESS
```
