Skip to main content

Terraform Cloud

HashiCorp's managed platform for Terraform โ€” remote state storage, locked execution environments, team access controls, cost estimation, and Sentinel policy enforcement with zero infrastructure to manage.

โœ“ Remote state & locking โœ“ VCS-driven plan/apply โœ“ Sentinel policy enforcement โœ“ GitHub Actions integration

What is Terraform Cloud?

Terraform Cloud (TFC) is HashiCorp's managed SaaS platform that extends open-source Terraform with collaboration, security, and governance features. At its core it solves three problems that arise when teams use Terraform: state management (where is the state file and who can access it?), execution consistency (runs on different machines produce different results due to different provider versions), and team workflows (who approved this apply and when?).

TFC organizes work into workspaces โ€” each workspace is an isolated Terraform working directory with its own state, variables, run history, and access controls. Workspaces map loosely to environments (dev/staging/prod) or infrastructure components (vpc/eks/rds). Runs (plans and applies) execute on HashiCorp-managed compute in an isolated, reproducible environment.

Configuring Remote State

Add the cloud block to your Terraform configuration to store state in Terraform Cloud:

# main.tf โ€” configure Terraform Cloud backend
terraform {
  required_version = ">= 1.1.0"

  cloud {
    organization = "my-org"

    workspaces {
      name = "api-production"
    }
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

# Authenticate via environment variable or interactive login
# export TF_TOKEN_app_terraform_io="your-api-token"
# OR run: terraform login

VCS-Driven Workflow (GitHub Integration)

Connect a workspace to your GitHub repository for automatic plan-on-PR and apply-on-merge workflows:

# In Terraform Cloud UI:
# Workspace โ†’ Settings โ†’ Version Control โ†’ Connect to VCS
# Install the Terraform Cloud GitHub App
# Select repository and configure:
#   - Working directory: infra/aws/production
#   - Trigger: Only files in working directory
#   - Auto apply: enabled for main branch only

# PR workflow (automatic):
# 1. Developer opens PR โ†’ TFC runs terraform plan
# 2. Plan output posted as PR comment
# 3. Reviewer approves the plan in TFC UI
# 4. PR merged โ†’ TFC runs terraform apply automatically
# 5. Apply output stored in run history with committer identity

Cross-Workspace Remote State

# In producer workspace (vpc-production), expose outputs:
output "vpc_id" {
  value = aws_vpc.main.id
}
output "private_subnet_ids" {
  value = aws_subnet.private[*].id
}

# In consumer workspace (eks-production), read remote state:
data "terraform_remote_state" "vpc" {
  backend = "remote"
  config = {
    organization = "my-org"
    workspaces = {
      name = "vpc-production"
    }
  }
}

resource "aws_eks_cluster" "main" {
  name     = "production"
  role_arn = aws_iam_role.eks.arn

  vpc_config {
    subnet_ids = data.terraform_remote_state.vpc.outputs.private_subnet_ids
  }
}

# Also enable remote state sharing in TFC:
# vpc-production workspace โ†’ Settings โ†’ Remote state sharing โ†’ Add eks-production

Sentinel Policy Enforcement

# policies/require-s3-versioning.sentinel
import "tfplan/v2" as tfplan

# Find all S3 bucket resources in the plan
s3_buckets = filter tfplan.resource_changes as _, rc {
  rc.type is "aws_s3_bucket" and
  rc.mode is "managed" and
  rc.change.actions contains "create"
}

# Policy rule: all new S3 buckets must enable versioning
main = rule {
  all s3_buckets as _, bucket {
    bucket.change.after.versioning[0].enabled is true
  }
}

# policy-set configuration (sentinel.hcl):
# policy "require-s3-versioning" {
#   source            = "./policies/require-s3-versioning.sentinel"
#   enforcement_level = "soft-mandatory"
# }

GitHub Actions Integration

# .github/workflows/terraform.yml
name: Terraform CI

on:
  pull_request:
    paths: ['infra/**']
  push:
    branches: [main]
    paths: ['infra/**']

jobs:
  terraform:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: infra/aws/production
    env:
      TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }}

    steps:
      - uses: actions/checkout@v4

      - uses: hashicorp/setup-terraform@v3
        with:
          terraform_version: "~1.7"
          cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

      - name: Terraform Init
        run: terraform init

      - name: Terraform Plan
        if: github.event_name == 'pull_request'
        run: terraform plan -no-color

      - name: Terraform Apply
        if: github.ref == 'refs/heads/main' && github.event_name == 'push'
        run: terraform apply -auto-approve

Terraform Cloud vs Terraform Enterprise vs Local

Feature Local / S3 Backend Terraform Cloud Terraform Enterprise
Hosting Self-managed HashiCorp SaaS Self-hosted
Remote state Manual (S3 + DynamoDB) Built-in, encrypted Built-in, encrypted
Remote execution No Yes Yes
Sentinel policies No Plus tier+ Yes (all tiers)
Cost estimation No Yes Yes
Data residency Full control HashiCorp US/EU Full control
Cost AWS S3 + DynamoDB fees Free (500 resources) / $20+ per user Enterprise contract

Best Practices

Frequently Asked Questions

What is Terraform Cloud and how does it differ from running Terraform locally?▼

Terraform Cloud is HashiCorp's managed service that provides remote state storage, a locked execution environment, team access controls, cost estimation, and Sentinel policy enforcement โ€” all in the cloud. When running Terraform locally, state files live on your machine or an S3 bucket you manage, runs execute on your laptop (with your environment variables), and there is no built-in team collaboration or audit trail. Terraform Cloud centralizes all of this: state is encrypted and versioned automatically, runs are reproducible in an isolated environment, and every plan and apply is logged with who triggered it.

How does VCS-driven (GitHub) workflow work in Terraform Cloud?▼

Connect your Terraform Cloud workspace to a GitHub repository. When you open a pull request, Terraform Cloud automatically runs terraform plan and posts the plan output as a PR comment. When the PR is merged to the main branch, Terraform Cloud runs terraform apply automatically. This creates a GitOps-style workflow where infrastructure changes go through code review before being applied. You configure the VCS connection in workspace settings by installing the Terraform Cloud GitHub App and specifying the working directory and trigger patterns.

What is the difference between Terraform Cloud and Terraform Enterprise?▼

Terraform Cloud is the SaaS offering hosted by HashiCorp at app.terraform.io โ€” you do not manage the infrastructure running it. Terraform Enterprise is the self-hosted version you install on your own servers (VM or Kubernetes), giving you full control over data residency, network isolation, and compliance requirements. Terraform Enterprise also includes additional enterprise features like audit logging, SAML/SSO integration, and higher Sentinel tier limits. Most teams start with Terraform Cloud Free or Plus tiers and only move to Enterprise for strict data sovereignty requirements.

How do I use remote state in Terraform Cloud from another workspace?▼

In your consumer workspace, declare a terraform_remote_state data source pointing to the producer workspace: data terraform_remote_state vpc { backend = 'remote' config = { organization = 'my-org' workspaces = { name = 'vpc-prod' } } }. Then reference outputs: data.terraform_remote_state.vpc.outputs.vpc_id. You must also enable 'Remote state sharing' in the producer workspace settings under General > Remote state sharing and add the consumer workspace to the allow list. This is how you compose infrastructure across multiple workspaces without hardcoding values.

What is Sentinel policy enforcement in Terraform Cloud?▼

Sentinel is HashiCorp's policy-as-code framework embedded in Terraform Cloud. You write policies in Sentinel language that run between the plan and apply phases. Policies can enforce rules like 'all S3 buckets must have versioning enabled' or 'no instance type larger than t3.xlarge is allowed in dev'. Policies have three enforcement modes: advisory (pass/fail logged but apply continues), soft-mandatory (can be overridden by a privileged user), and hard-mandatory (blocks apply unconditionally). Sentinel is available on Terraform Cloud Plus and Terraform Enterprise.

How do I integrate Terraform Cloud with GitHub Actions?▼

Use the hashicorp/setup-terraform GitHub Action to install Terraform, then authenticate to Terraform Cloud using a TFC API token stored as a GitHub secret. Set TF_API_TOKEN in your workflow environment. On pull_request events, run terraform plan; on push to main, run terraform apply. Alternatively, use Terraform Cloud's native VCS integration which avoids managing tokens in GitHub and provides richer plan output in the TFC UI. The native VCS integration is recommended for most teams as it provides better visibility and audit trails.

Share this tool: X / Twitter LinkedIn
โœ“ 60,000+ developers use DevPlaybook โ˜…โ˜…โ˜…โ˜…โ˜… 4.8 / 5 on Gumroad โœ“ MIT licensed ยท Instant download โœ“ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • โšก AI Code Review, Doc Generator & SQL Builder
  • โšก All premium templates & early access
  • โšก Member discounts on Gumroad products
Start Free Trial โ†’

$9/mo after trial ยท Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products โ€” grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro โ€” $79 โ†’

MIT licensed ยท Instant download ยท No subscription

See what's included โ†’ Browse all deals โ†’