How to configure your environment

How to configure your environment

Understanding regions and zones

Certain Google Compute Engine resources live in regions or zones.

A region is a specific geographical location where you can run your resources. Each region has one or more zones. For example, the us-central1 region denotes a region in the Central United States that has zones us-central1-a, us-central1-b, us-central1-c, and us-central1-f.

Resources that live in a zone are referred to as zonal resources.

Virtual machine instances and persistent disks live in a zone.

If you want to attach a persistent disk to a virtual machine instance, both resources must be in the same zone. Similarly, if you want to assign a static IP address to an instance, the instance must be in the same region as the static IP address.

To see what your default region and zone settings are, run the following commands:

gcloud config get-value compute/region
gcloud config get-value compute/zone

If the google-compute-default-region or google-compute-default-zone responses are (unset), that means no default zone or region is set.

How to identify your default zone and region

  1. Copy and paste your project ID to your clipboard or text editor.

  2. In Cloud Shell, run the following gcloud command, replacing with the project ID you copied:

gcloud compute project-info describe --project <your_project_ID>

If the google-compute-default-region and google-compute-default-zone keys and values are missing from the output, no default zone or region is set.

Setting Environment Variables

Environment variables define your environment and help save time when you write scripts that contain APIs or executables.

To create an environment variable to store your Project ID run:

export PROJECT_ID=<your_project_ID>

Replace <your_project_ID> with the value for name from the gcloud compute project-info describe command you ran earlier.

To create an environment variable to store your Zone run:

export ZONE=<your_zone>

But replace <your_zone> with the value for zone from the gcloud compute project-info describe command you ran earlier.

For verification, run the following commands:

echo $PROJECT_ID
echo $ZONE

If the variables were set correctly, the echo commands will output your Project ID and Zone.