Skip to main content
In this guide, we’ll walk through configuring and running Terraform Cloud Workspaces using local execution mode. Follow each step to authenticate, set up AWS credentials, create your workspace, and manage your infrastructure—all from your local machine.
The image shows a KodeKloud lab interface for "Terraform Cloud Workspace - Local Execution," with instructions and shortcuts for using VS Code on the left and a file explorer with a README.md file open on the right.

Table of Contents

  1. Authenticate the CLI with Terraform Cloud
  2. Configure AWS Credentials
  3. Create a Terraform Cloud Workspace
  4. Match Versions & Set Execution Mode
  5. Initialize, Plan, and Apply
  6. Verify in Terraform Cloud
  7. Tear Down Infrastructure

1. Authenticate the CLI with Terraform Cloud

First, log in to Terraform Cloud from your terminal:
Follow the on-screen prompts to generate a new API token.
The image shows a web interface for creating an API token on Terraform Cloud, with a dialog box prompting for a description.
When prompted, paste your API token into the terminal. Successful authentication will display your user ID and a confirmation message.

2. Configure AWS Credentials

Export your AWS credentials as environment variables:
Never commit your AWS credentials or API tokens to version control. Use environment variables or a secrets manager.
These lab environments automatically tear down after one hour, so your temporary credentials remain safe.

3. Create a Terraform Cloud Workspace

In Terraform Cloud’s web UI:
  1. Select your organization.
  2. Click New Workspace → CLI-driven workflow.
  3. Enter:
    • Name: devops-aws-myapp-dev
    • Description: Development environment for MyApp on AWS.
The image shows a web interface for creating a new workspace in Terraform Cloud, with fields for entering a workspace name and description. There are options to configure settings and buttons to create or cancel the workspace creation.
Add the following backend configuration to backend.tf (or your chosen .tf file):

4. Match Versions & Set Execution Mode

Ensure your local Terraform version matches the workspace setting:
In Terraform Cloud’s UI, go to Workspace → Settings → General, then:
  • Set Terraform Version to match your local client.
  • Change Execution Mode to Local.
  • Save your changes.
The image shows the General Settings page of a Terraform Cloud workspace, with fields for ID, Name, Description, Execution Mode, and Remote State Sharing options.

5. Initialize, Plan, and Apply

Initialize your local directory and review the execution plan:
Expected plan output:
Apply your configuration:
Sample apply summary:

6. Verify in Terraform Cloud

Navigate to Workspace → Runs and inspect the latest run. You’ll see resource details and outputs:

7. Tear Down Infrastructure

When testing is complete, destroy all resources:
Confirm the teardown:

Watch Video

Practice Lab