CLI Workflow

The CLI workflow is nice this because it offers the best of both worlds. You get to use the familiar CLI. At the same time, the terraform apply runs remotely in a throwaway virtual machine. So you get a consistent environment.

Summary

To use the CLI-driven workflow:

  1. Configure backend.tf with the remote backend
  2. Configure Terraform Cloud Variables
  3. Use the CLI to deploy as normal

1. Configure backend.tf with the remote backend

To use Terraform Cloud, we configure the backend to “remote”.

Instructions: Terraform Cloud Backend

2. Configure Terraform Cloud Variables

When you set up multiple Terraform Cloud Workspaces, you often repeatedly set up common workspace Terraform Variables and Environment Variables. Terraspace supports automating much of this process. You can configure Terraform Cloud Variables with either JSON or a DSL:

3. Use the CLI to deploy as normal

Then it’s just running the same CLI as you would normally run

terraspace up demo

Terraspace detects that TFC is configured, automatically creates the workspace, configures it, and runs terraform remotely.

Note, if your TFC user does not have permission to create the workspace, then contact your admin to precreate the workspace ahead of time.

Terraform Recommendations

A quick note. Terraform recommends managing infrastructure in smaller Terraform configurations.

You shouldn’t use a single Terraform workspace to manage everything that makes up your production or staging environment. Instead, make smaller workspaces that are easy to delegate. One Workspace Per Environment Per Terraform Configuration.

A workspace provides a “namespace” for all the resources contained in an environment and configuration. Essentially, you create separate workspaces with separate statefiles.

More tools: