Skip to main content
Many teams begin with Terraform Open Source (OSS) on their local machines before transitioning to Terraform Cloud for enhanced collaboration, state management, and run governance. This guide walks you through migrating your existing Terraform OSS setup to Terraform Cloud without destroying your current AWS infrastructure.

Table of Contents

  1. Prerequisites
  2. Clone and Apply Locally
  3. Configure Terraform Cloud Backend
  4. Initialize and Migrate State
  5. Trigger Runs via CLI
  6. Comparison: OSS vs. Cloud
  7. References

Prerequisites

  • Terraform OSS installed (v1.0+).
  • AWS CLI configured or valid AWS credentials.
  • A Terraform Cloud account and organization.
  • Git installed.
Never commit your AWS credentials or Terraform Cloud API tokens to version control. Use environment variables or a secrets manager.

Clone and Apply Locally

First, clone the HashiCat AWS repository and navigate into it:
The image shows a KodeKloud lab interface for migrating to Terraform Cloud, with instructions to clone a GitHub repository and a terminal window open on the right.
Set your AWS credentials using environment variables:
Inspect the existing Terraform configuration in main.tf:
Initialize the working directory and apply:
You should see output similar to:
Your AWS infrastructure is now managed locally by Terraform OSS.

Configure Terraform Cloud Backend

To migrate state to Terraform Cloud, update main.tf with a cloud block:
Log in to Terraform Cloud via the CLI:
This command prompts you to authorize Terraform Cloud access and stores your API token in ~/.terraform.d/credentials.tfrc.json.

Initialize and Migrate State

Reinitialize your directory so Terraform switches the backend to Terraform Cloud:
On success, you’ll see:
Now, run a plan and apply. Terraform will handle state migration automatically:
Once complete, your state is stored remotely in Terraform Cloud. You can manage runs, view logs, and set policies from the Terraform Cloud UI:
The image shows a Terraform Cloud interface displaying a list of workspaces with their run statuses, repository links, and latest change timestamps. The sidebar includes options for managing workspaces, registry, and settings.

Trigger Runs via CLI

To explicitly specify a workspace name, update your cloud block:
Commit and push these changes to your version control system (if connected). Or, trigger the run directly:
CLI output will indicate a remote run:
The image shows a Terraform Cloud interface with a workspace named "devops-aws-hashicat-dev" where a plan is running, triggered via CLI. It includes navigation options on the left and a notification about improved navigation.
Upon completion, your Terraform Cloud workspace will reflect the latest state, and your AWS infrastructure remains intact throughout the migration.

Comparison: Terraform OSS vs. Terraform Cloud


References

Watch Video

Practice Lab