5 Helpful Commands for Cloud Workstations

Nathaniel (Nate) Avery
Google Cloud - Community
3 min readJun 15, 2023
Cloud Workstations Logo

Google’s Cloud Workstations is a powerful and flexible solutions for developers looking for a hosted IDE. Most users will work with it via the Google Cloud console. The console is well laid out and easy to get around, but some folks are more comfortable using a CLI. This could be for a number of reasons. Maybe it’s because they want to leverage automation, or maybe they find it faster to issue start/stop commands. Side note: Terraform is another automation option supported by Cloud Workstations. Whatever the reason, there are a few CLI commands that are worth knowing. There are also situations where Google Cloud console access may be discouraged by the organization.

I’ve written this blog post because I learn best when I see examples. If you’re like me, then maybe these will help.

These commands can be executed by anyone with the proper IAM permissions. The issuer will also need some knowledge of how Cloud Workstations has been configured for their organization. Some non-obvious things the issuer will need to know are:

  • Cloud Workstations cluster name
  • Cloud Workstations configuration name
  • Cloud Workstations region

Note: Please be sure to install the latest version of the gcloud CLI.

Full List of Commands

Before we begin, let’s look at the full list of commands.


//==================[]==============================================\\
|| Command || Description ||
|]==================[]==============================================[|
|| create || Create a workstation. ||
|| delete || Delete a workstation ||
|| describe || Describe a workstation ||
|| get-iam-policy || Get the IAM policy for a workstation ||
|| list || List workstations ||
|| list-usable || List usable workstations ||
|| set-iam-policy || Set the IAM policy for a workstation ||
|| ssh || SSH into a running workstation ||
|| start || Start a workstation ||
|| start-tcp-tunnel || Start a tunnel through which a local process ||
|| _ || can forward TCP traffic to the workstation ||
|| stop || Stop a workstation ||
\\==================[]==============================================//

1. List Workstations available to you

This command returns a list of all workstations the user has access to as defined in IAM permissions. There is a similar command, — list, which returns all workstations regardless of access permissions.

Syntax:

gcloud beta workstations list-usable
(--config=CONFIG : --cluster=CLUSTER --region=REGION)
[--filter=EXPRESSION] [--limit=LIMIT] [--page-size=PAGE_SIZE]
[--sort-by=[FIELD,...]] [GCLOUD_WIDE_FLAG ...]

Example:

gcloud beta workstations list-usable \
--config=basic-configuration-codeoss \
--cluster=cluster-us-east-4-va \
--region=us-east4

2. Start a Workstation

Syntax:

gcloud beta workstations start
(WORKSTATION : --cluster=CLUSTER --config=CONFIG --region=REGION)
[--async] [GCLOUD_WIDE_FLAG ...]

Example:

gcloud beta workstations start workstation-oss \
--cluster=cluster-us-east-4-va \
--config=basic-configuration-codeoss \
--region=us-east4

3. Stop a Workstation

Syntax:

gcloud beta workstations stop
(WORKSTATION : --cluster=CLUSTER --config=CONFIG --region=REGION)
[--async] [GCLOUD_WIDE_FLAG ...]

Example:

gcloud beta workstations stop workstation-oss \
--cluster=cluster-us-east-4-va \
--config=basic-configuration-codeoss \
--region=us-east4

4. Start a TCP Tunnel

Syntax:

gcloud beta workstations start-tcp-tunnel
(WORKSTATION : --cluster=CLUSTER --config=CONFIG --region=REGION)
WORKSTATION_PORT
[--local-host-port=LOCAL_HOST_PORT; default="localhost:0"]
[GCLOUD_WIDE_FLAG ...]

Example:

gcloud beta workstations start-tcp-tunnel \
--project=riccardo-blog-test-v1 \
--cluster=cluster-us-east-4-va \
--config=basic-configuration-codeoss \
--region=us-east4 \
--local-host-port=:2222 \
workstation-oss 22

5. SSH into a Running Workstation

Syntax:

    gcloud beta workstations ssh
(WORKSTATION : --cluster=CLUSTER --config=CONFIG --region=REGION)
[--command=COMMAND] [--port=PORT; default=22]
[--user=USER; default="user"] [GCLOUD_WIDE_FLAG ...] [-- SSH_ARGS ...]

Example:

gcloud beta workstations ssh workstation-oss \
--cluster=cluster-us-east-4-va \
--config=basic-configuration-codeoss \
--region=us-east4

Conclusion

Hopefully these syntax examples will aide anyone looking to use the CLI to control Cloud Workstations.

--

--

Nathaniel (Nate) Avery
Google Cloud - Community

Tech enthusiast who loves, IT, video games, and pop culture. I currently work for Google, however, views are my own.