06/13/2023 22:36 | Category: terraform

Tags: github_actionsmakefilebashterraformiac

github actions fails terraform workspace init or create legacy method

When working on a pipeline using GitHub Actions I was deploying some code with a Terraform command that creates a Terraform workspace.

The command used was this:

terraform workspace new dev || terraform workspace select dev

Which produced an unfortunate exit status inside GitHub actions:

Workspace "dev" already exists
Error: Terraform exited with code 1.

This lead the worker to begin cancelation of the job and proceed with failing, even though the second end of the command succeeded.

To avoid this, I swapped to using the new (in Terraform version 1.4.0) -or-create flag.

Newly minted command for the CICD pipeline is:

terraform workspace select -or-create dev