Image for post
Image for post

Getting Started with GCloud SDK: Part 1

Path toward Infrastructure As Code with Bash

So you just downloaded GCloud SDK and followed the instructions to authorize the your shell environment to get started on the path to automation funky town.

The Setup

Set the default project and service account:

export GCP_SERVICE_ACCT=$(gcloud iam service-accounts list \
--filter='email ~ [0-9]*-compute@.*' \
--format='table(email)' \
| grep -v EMAIL
export GCP_PROJECT=$(gcloud config list \
--format 'value(core.project)'

The Basic Script

These are the pieces of the basic script.

Step 1: Verify Environment Setup

First let’s check the required environment variables that we set earlier:

Step 2: Set the Scopes

This simply constructs a list of Scope URLs that we use to grant permissions to our virtual instances we will create.

Step 3: Distributing Instances across Zones

In this example, one instance will be placed in every zone in the current region. This gives us high available, should one zone (data center) go down, the other two zones will be available. Distributing instances across zones in a region is a common practice.

Step 4: Creating Systems

Now we can create three systems using gcloud compute instances create command:

To Be Continued…

This is a small introduction to what you can do with gcloud tool and bash. Though this is some automation, it is not quite IaC (Infrastructure As Code) yet, because the code is hardwired for three instances explicitly named es-*.

Written by

Linux NinjaPants Automation Engineering Mutant — exploring DevOps, Kubernetes, CNI, IAC

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store