Creating A Terraform Workspace If It Doesn't Exist

Today, I needed to add a step to my GitHub Actions workflow to create a Terraform workspace if it doesn’t exist.

You can do that like this:

terraform init
terraform workspace select -or-create <workspace name>

See: https://developer.hashicorp.com/terraform/cli/commands/workspace/select


Master GitHub Actions with a Senior Infrastructure Engineer

As a senior staff infrastructure engineer, I share exclusive, behind-the-scenes insights that you won't find anywhere else. Get the strategies and techniques I've used to save companies $500k in CI costs and transform teams with GitOps best practices—delivered straight to your inbox.

Not sure yet? Check out the archive.

Unsubscribe at any time.