Introduction

Have you ever found yourself in a situation where your code runs flawlessly on your computer but fails miserably on a colleague’s machine? In the fast-paced world of creating software, one big problem teams often face is that their computer setups can be very different. This means something that works well on one person’s computer might not work on someone else’s.

Google Cloud Workstations is a great tool that helps solve this problem by making everyone’s computer setup the same. ​​Recognizing this, we embraced these workstations in our client projects, a strategic move that has significantly enhanced our operational efficiency. By standardizing the computing environments across our projects, Google Cloud Workstations has become an invaluable asset, ensuring that our solutions are as robust and reliable on our clients’ systems as they are on ours. With this solution, gone is the time where onboarding a new engineer with his/her laptop would take days. Now you can do this in a matter of minutes and automate the entire process via Infrastructure as Code.

What is it about?

The benefits of using Cloud workstations (i.e. that are actually laptops on the cloud) are multiple:

Easy-to-Share Setups

Google Cloud Workstations lets all the developers in a team use the same computer setup. This means everyone has the same tools and programs, which makes it easier to work together. It solves the problem where something works for one person but not for another, making everything more smooth and less frustrating.

Everything You Need, Ready to Use

When you start using a Google Cloud Workstation, it’s like opening a toolbox that already has all the tools you need. It comes with software, helpful programs for writing code, and even some pre-loaded files to get you started. This means you can jump straight into your work without having to spend time getting everything set up. You also have the possibility to set up some startup scripts that will run when the workstation starts. This gives you full control over the environment and lets you configure your machine for the exact purpose you want.

Quick Setup with Terraform

Setting up these workstations is super easy, especially with Terraform. With Terraform resources, you can set up your workstation cluster and configuration quickly and without mistakes. With just a few lines of code, you can have everything ready to go in just a few minutes, which is a big time-saver. It also allows you to deploy new workstations for new users by just adding them dynamically and reusing existing configurations. You don’t need to set up everything over and over again, like you would do on multiple physical machines for each one of your new developers.

Smart Help with Duet AI

Google Cloud Workstations have a special feature called Duet AI. It’s like having a smart assistant that can help you write code faster, suggest improvements, and even chat with you to help solve problems. This makes building apps and software much quicker and can help anyone, whether you’re new to coding or have been doing it for years.

Safe and Secure

Another great thing about Google Cloud Workstations is that they’re very secure. They work inside your company’s own VPC, which means all the work you do and the code you write stays safe and private. It’s like having a secure workshop in the cloud where you can work without worrying about outsiders getting in.

Adding Git Repositories Automatically

In our setup, we’ve made it really easy for developers to get started by automatically adding important Git repositories to their workstations as soon as they log in. This means that all the basic code they need to start working is already there waiting for them. They don’t have to spend time cloning this code themselves.

FinOps

Using Google Cloud Workstations can save your company money and make things easier for your engineers. Instead of needing expensive, high-power laptops, your engineers just need a simple way to log in to their workstation. This means all the heavy computer work is done in the cloud, not on their personal computers. Plus, a great feature is that these workstations can turn off by themselves when no one is using them for a while, and turn back on when needed.

In a nutshell, when developers don’t have to worry about setting up their environment and can find all the code they need right away, they can start coding faster. It also means everyone is working with the same code from the start, which helps avoid problems where something works for one person but not for another.

Implementation

Implementing a Google Cloud Workstation environment involves several key steps:

  1. building a custom Docker image tailored to your development needs

  2. deploying a workstation cluster using Terraform

  3. dynamically provisioning workstations for each new developer.

This section dives into each of these processes, offering insights into the code and configurations that bring this scalable and flexible development environment to life.

Building a Custom Docker Image

Dockerfile commands for setting up a development environment with zsh, Python, and Oh My Zsh with Powerlevel10k theme on a Google Cloud Workstation, including installation of dbt and poetry packages, and a workstation customization script

We begin with a Dockerfile designed to construct a tailored image for our workstations. We start from a base image pre-equipped with Code-OSS, providing a familiar and versatile IDE for developers right out of the box.

The first order of business is to update our system and install essential tools such as zsh, a favorite among developers for its customization capabilities, and gnupg and software-properties-common for added security and management.

We then enhance our shell experience with Oh My Zsh and the Powerlevel10k theme, making our terminal not only more intuitive but also visually appealing. This setup is complemented by essential Python tools and packages like dbt-core and poetry, gearing our environment towards data manipulation and project management.

To top it off, we incorporate a custom script to further personalize the workstation setup, allowing for additional configurations and preferences to be applied seamlessly upon startup. These scripts run automatically and do a couple of things: they download the repositories with the code everyone needs, and they set up necessary environment variables like DBT_PROFILES_DIR for example, for running their dbt projects. This is a setting that some developers need for their work, and having it ready to go saves time.

Deploying with Terraform

With our Docker image ready, we turn to Terraform to orchestrate our workstation infrastructure. We define a google_workstations_workstation_cluster resource, essentially carving out a dedicated space in Google Cloud for our workstations to reside. This includes specifying network settings and choosing an appropriate geographical location for our cluster.

Next, we detail our workstation configuration using google_workstations_workstation_config. This includes selecting the machine specs, defining the boot disk size, and opting for a custom container image. We also ensure data persistence by setting up persistent directories, a crucial aspect for maintaining workspace integrity over time.

A Dockerfile displaying a sequence of commands for configuring a Google Cloud Workstation with essential tools like zsh, Python, and Oh My Zsh's Powerlevel10k theme, as well as Python packages such as dbt and poetry

The magic happens when we dynamically deploy workstations for each developer using the google_workstations_workstation resource. By iterating over a list of users’ emails, we create personalized workstations, ensuring every team member has a tailored development environment ready at their fingertips.

Lastly, we secure our setup with proper IAM configurations, granting the necessary permissions for developers to access and operate their workstations within the Google Cloud ecosystem.

Screenshot of Terraform configuration code for setting up Google Workstation resources and IAM roles. The code includes a 'google_workstations_workstation' resource block, a 'google_workstations_workstation_iam_member' block for assigning user roles, and a 'google_project_iam_member' block for operation viewer permissions, utilizing variables for user emails, project ID, and region.


Conclusion

Google Cloud Workstations make the whole process of getting started coding easier and more unified for teams. They remove common headaches like setting up your environment or dealing with security worries. Plus, with tools like Duet AI, they offer a helping hand to speed up your work. Whether you’re part of a big team or just starting out, Google Cloud Workstations can make your coding journey smoother and more enjoyable.

Thank you

If you enjoyed reading this article, stay tuned as we regularly publish technical articles on dbt, Google Cloud and how to secure those tools at best. Follow Astrafy on LinkedIn to be notified for the next article ;).

If you are looking for support on Data Stack or Google Cloud solutions, feel free to reach out to us at sales@astrafy.io.