Terraform for Teams: Remote State, Workspaces, and Best Practices

How to structure Terraform so teams can collaborate without stepping on each other's toes. S3 remote state, workspaces, reusable modules, and CI/CD strategies.

The Problem: Solo Terraform vs Team Terraform

Terraform feels effortless when working solo. The challenge begins when your team grows and familiar questions start popping up:

  • “Who has the latest state file?”
  • “Why does my plan show changes I didn’t make?”
  • “How do we prevent two engineers from running apply at the same time?”

Remote State with S3 + DynamoDB

Rule number one of Terraform in a team: never store state locally.

# backend.tf
terraform {
  backend "s3" {
    bucket         = "my-company-terraform-state"
    key            = "production/networking/terraform.tfstate"
    region         = "eu-west-1"
    encrypt        = true
    dynamodb_table = "terraform-locks"
  }
}

# Create the state lock table
resource "aws_dynamodb_table" "terraform_locks" {
  name         = "terraform-locks"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "LockID"

  attribute {
    name = "LockID"
    type = "S"
  }

  tags = {
    Name        = "terraform-state-locks"
    Environment = "shared"
  }
}

Scalable Project Structure

infrastructure/
├── modules/
│   ├── networking/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   │   └── README.md
│   ├── eks-cluster/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   └── outputs.tf
│   └── monitoring/
│       ├── main.tf
│       ├── variables.tf
│       └── outputs.tf
├── environments/
│   ├── production/
│   │   ├── main.tf
│   │   ├── backend.tf
│   │   ├── variables.tf
│   │   └── terraform.tfvars
│   ├── staging/
│   │   ├── main.tf
│   │   ├── backend.tf
│   │   └── terraform.tfvars
│   └── dev/
│       ├── main.tf
│       └── terraform.tfvars
└── .github/
    └── workflows/
        └── terraform.yml

CI/CD Pipeline for Terraform

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

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

jobs:
  plan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v3
        with:
          terraform_version: 1.7.0

      - name: Terraform Init
        run: terraform init
        working-directory: infrastructure/environments/production

      - name: Terraform Plan
        run: terraform plan -out=tfplan -no-color
        working-directory: infrastructure/environments/production

      - name: Comment PR with Plan
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          script: |
            const output = `#### Terraform Plan 📖
            \`\`\`
            ${process.env.PLAN}
            \`\`\`
            *Pushed by: @${{ github.actor }}*`;

  apply:
    needs: plan
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Terraform Apply
        run: terraform apply -auto-approve tfplan
        working-directory: infrastructure/environments/production

Best Practices

  1. Use modules for reusable infrastructure patterns
  2. Version your modules using Git tags
  3. Never hardcode values — use variables and tfvars
  4. Split state by blast radius: separate networking, compute, and data stores
  5. Policy as Code: enforce guardrails with OPA or terraform-compliance

Conclusion

Running Terraform at team scale requires discipline, but with remote state locking, modular boundaries, and automated PR plans, it becomes a rock-solid foundation for collaborative infrastructure engineering.


Have your own battle-tested Terraform setup? Let me know on X.