← Back to Blog

Terraform Cloud Migration Guide

šŸ“… 2025-11-06T12:23:21.540Zā±ļø 6 min readāœļø Robson Alves
#terraform#devops#cloud
Terraform Cloud Migration Guide

Terraform Cloud Migration Guide

You've been managing your infrastructure as code using Terraform locally, but now you're considering moving to Terraform Cloud. This transition can streamline collaboration and enhance version control, making it easier for teams to manage and deploy infrastructure.

In 2025, cloud-native practices will continue to evolve, emphasizing automation and centralized management. Migrating to Terraform Cloud ensures your infrastructure remains agile and secure while aligning with industry standards.

By the end of this guide, you'll learn how to migrate your existing Terraform configurations to Terraform Cloud, including setting up workspaces, managing variables, and integrating with version control systems.


Understanding Terraform Cloud

Terraform Cloud provides a centralized platform for teams to collaborate on infrastructure management. It offers features like remote state storage, collaboration tools, and policy enforcement, making it easier to manage complex environments.

Key benefits include improved security through encrypted state data, enhanced visibility via run history, and automated workflows with the ability to integrate with other tools.


Preparing for Migration

Before starting the migration, ensure you have a backup of your local Terraform configurations. This step is crucial to avoid losing any important settings or states during the transition.

Step 1: Account Setup

Create a Terraform Cloud account if you don't already have one. Sign up at Terraform Cloud and log in to access your dashboard.

# Open Terraform Cloud in browser
open https://app.terraform.io/

Step 2: Prepare Your Configurations

Ensure all your local Terraform configurations are clean, well-documented, and free of errors. This step helps avoid issues during the migration process.


Setting Up Workspaces

Workspaces in Terraform Cloud allow you to manage multiple environments (e.g., development, staging, production) within a single organization. Each workspace can have its own set of variables and state data.

Step 3: Create New Workspaces

Navigate to your organization dashboard in Terraform Cloud and create new workspaces for each environment you need.

# Example HCL configuration snippet for creating a workspace via API
resource "tfe_workspace" "dev" {
  name         = "development"
  organization = "my-organization"
}

This code creates a new workspace named "development" in the specified organization.


Migrating State Data

State data in Terraform Cloud is stored remotely, ensuring it's secure and accessible to all team members. You need to migrate your local state files to Terraform Cloud.

Step 4: Initialize Remote Backend

Update your main.tf file to use the remote backend provided by Terraform Cloud.

# Configure remote backend for Terraform Cloud
terraform {
  backend "remote" {
    organization = "my-organization"

    workspaces {
      name = "development"
    }
  }
}

This configuration sets up the remote backend, specifying your organization and workspace.


Managing Variables

Variables in Terraform Cloud are managed centrally, allowing you to define sensitive data securely. This section covers how to migrate and manage variables.

Step 5: Define Workspace Variables

In your new workspaces, define any necessary environment-specific variables. Use the "Variables" tab in each workspace for this purpose.

# Example command to set a variable via API
curl --request POST \
     --header "Authorization: Bearer $TOKEN" \
     --header "Content-Type: application/vnd.api+json" \
     --data '{"data": {"type":"vars","attributes":{"key":"region","value":"us-west-2","category":"terraform"}}}' \
     https://app.terraform.io/api/v2/workspaces/ws-MYWORKSPACEID/vars

This API call creates a new variable named "region" with the value "us-west-2".


Integrating with Version Control

Integrating your Terraform configurations with a version control system (VCS) in Terraform Cloud automates the workflow and enhances collaboration.

Step 6: Connect VCS Repository

Connect your Terraform Cloud workspace to a repository in your chosen VCS provider. This step allows Terraform Cloud to pull configurations automatically.

# Example command to connect GitHub repository
curl --request POST \
     --header "Authorization: Bearer $TOKEN" \
     --header "Content-Type: application/vnd.api+json" \
     --data '{"data": {"type":"workspaces","attributes":{"name":"development"},"relationships":{"organization":{"data":{"id":"my-organization","type":"organizations"}},"vcs-repo":{"data":{"attributes":{"identifier":"my-org/my-repo","branch":"main"},"type":"vcs-repos"}}}}}' \
     https://app.terraform.io/api/v2/organizations/my-organization/workspaces

This command connects the "development" workspace to a GitHub repository.


Automating CI/CD Workflows

Automated workflows in Terraform Cloud can streamline your deployment process, ensuring changes are applied consistently and reliably.

Step 7: Configure Webhooks

Set up webhooks in your VCS provider to trigger runs in Terraform Cloud whenever changes are pushed to the connected repository.

# Example webhook configuration for GitHub
name: Terraform Cloud Trigger
on:
  push:
    branches:
      - main
jobs:
  terraform-cloud-run:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run Terraform Cloud Plan
        run: |
          curl --request POST \
               --header "Authorization: Bearer ${{ secrets.TFC_TOKEN }}" \
               https://app.terraform.io/api/v2/runs \
               --data '{"data":{"attributes":{},"relationships":{"workspace":{"data":{"type":"workspaces","id":"ws-MYWORKSPACEID"}}}}}'

This GitHub Actions workflow triggers a plan run in Terraform Cloud whenever changes are pushed to the main branch.


Troubleshooting Common Issues

Migration can sometimes encounter issues. Here are some common problems and their solutions.

Issue: State Migration Errors

Symptom: Errors during state migration might occur if your local state file is corrupted or not compatible with the remote backend. Solution: Validate your local state file and ensure compatibility by running terraform init locally before migrating to Terraform Cloud.

# Validate local state file
terraform validate

Issue: Variable Conflicts

Symptom: Conflicting variable values between local configurations and Terraform Cloud can cause errors. Solution: Review and resolve any conflicting variables in both environments before applying changes.

āš ļø Warning: Always test migrations in a staging environment before deploying to production to catch and resolve issues early.


Conclusion

Migrating from local Terraform to Terraform Cloud offers numerous benefits, including improved collaboration, enhanced security, and streamlined workflows. By following the steps outlined in this guide, you can successfully transition your infrastructure management to Terraform Cloud, ensuring your team remains agile and efficient.

Key Takeaways:

  1. Prepare your configurations by backing up local state data.
  2. Set up workspaces and migrate state files securely.
  3. Manage variables centrally for better security and consistency.
  4. Integrate with version control systems for automated workflows.
  5. Test migrations thoroughly in a staging environment before production deployment.

Cost Considerations

Terraform Cloud offers different pricing tiers based on usage. Here's a comparison of the Free and Professional plans:

FeatureFree PlanProfessional Plan
Workspaces3Unlimited
Concurrent Runs120
Private ModulesNoYes
Cost$0/moStarting at $50/mo

Choose the plan that best fits your team's needs and budget.


By embracing Terraform Cloud, you'll be well-prepared for future infrastructure challenges, ensuring your deployments are efficient and secure.