DevOps & SRE

GCP DevOps tricks: Create a custom Cloud Shell image that includes Terraform and Helm

generic devops 2

If you develop or manage apps on Google Cloud Platform (GCP), you’re probably familiar with Cloud Shell, which provides you with a secure CLI that you can use to manage your environment directly from the browser. But while Cloud Shell’s default image contains most of the tools you could wish for, in some cases you might need more—for example, Terraform for infrastructure provisioning, or Helm, the Kubernetes package manager. 

In this blog post, you will learn how to create a custom Docker image for Cloud Shell that includes the Helm client and Terraform. At a high level, this is a two-step process:

  1. Create and publish a Docker image
  2. Configure your custom image to be used in Cloud Shell

Let’s take a closer look. 

1. Create and publish a custom Cloud Shell Docker image

First, you need to create new Docker image that's based on the default Cloud Shell image and then publish the image you created to Container Registry.

1. Create a new repo and set the project ID where the Docker image should be published:

  mkdir gcp-cloud-shell-custom-image
cd gcp-cloud-shell-custom-image

2.  With your file editor of choice, create a file named Dockerfile with the following content:




    unzip terraform_${TERRAFORM_VERSION} -d /bin && \
    wget -q${HELM_VERSION}-linux-amd64.tar.gz -O - | tar -xzO linux-amd64/helm > /usr/local/bin/helm && \
    chmod +x /usr/local/bin/helm && \
    rm -f terraform_${TERRAFORM_VERSION}

3. Build the Docker image:

  docker build -t$GCP_PROJECT_ID/cloud-shell-image .

4. Push the Docker image to Container Registry:

  docker push$GCP_PROJECT_ID/cloud-shell-image:latest

Note: You will need to configure Docker to authenticate with gcr by following the steps here.

2. Configure Cloud Shell image to use the published image

Now that you’ve created and published your image, you need to configure the Cloud Shell Environment to utilize the image that was published to Container Registry. In the Cloud Console follow these steps:

  1. Go to Cloud Shell Environment settings
  2. Click Edit
  3. Click "Select image from project"
  4. In the Image URL field enter:$GCP_PROJECT_ID/cloud-shell-image:latest
  5. Click "Save"Now open a new Cloud Shell session and you should see that the new custom image is used.

There you have it—a way to configure your Cloud Shell environment with all your favorite tools. To learn more about Cloud Shell, check out the documentation.