Workspaces in Cloud
Imagine your Lego city is now being built by a whole team. If everyone keeps their own local blueprint drawer (state file), chaos happens with different versions, conflicting changes, and lost progress.
Terraform Cloud solves this by storing the state remotely in a secure, shared vault, so the whole team works from the same blueprint. On top of that, workspaces act like labeled drawers for environments (dev, staging, prod), ensuring changes stay organized.
Key Concepts
1. Remote State in Terraform Cloud
- Definition: Terraform Cloud stores state files centrally, instead of locally.
- Benefits:
- Shared access for teams.
- Automatic state locking to prevent conflicts.
- Encrypted and backed up for security.
- Workflow:
- Push code → Terraform Cloud runs
planandapply. - State is updated in the Cloud, visible to all team members.
- Push code → Terraform Cloud runs
2. Workspaces in Terraform Cloud
- Definition: Workspaces separate environments (dev, staging, prod) within Terraform Cloud.
- Features:
- Each workspace has its own state file.
- Can be linked to different VCS branches.
- Supports environment‑specific variables and secrets.
- Example:
devworkspace → linked todevbranch.stagingworkspace → linked tostagingbranch.prodworkspace → linked tomainbranch.
3. Collaboration Benefits
- Consistency: Everyone works from the same state.
- Safety: State locking prevents simultaneous conflicting changes.
- Transparency: Run history shows who applied what, when.
- Flexibility: Workspaces allow environment separation without duplicating code.
Hands‑On Lab / Demo
Lab: Remote State & Workspaces Setup
- Create a new workspace in Terraform Cloud.
- Connect it to a GitHub repo.
- Push Terraform code → Terraform Cloud automatically runs
plan. - Observe:
- State file stored remotely.
- Workspace linked to branch.
- Team members can view logs and outputs.
Pro Tips & Best Practices
- Always use remote state for team projects.
- Organize workspaces by environment (
dev,staging,prod). - Use workspace variables for environment‑specific settings.
- Document workspace strategy in project README.
- Review run history regularly for auditing.
Summary & Cheatsheet
- Remote state = Shared, secure, locked state in Terraform Cloud.
- Workspaces = Environment separation with unique state files.
- Benefits: Collaboration, safety, transparency, flexibility.
Quick mnemonic: Cloud State = One Truth, Workspaces = Many Environments
The Hackers Notebook
Remote state and workspaces in Terraform Cloud are the foundation of team collaboration. Remote state ensures everyone works from the same blueprint, while workspaces keep environments organized and safe. Together, they eliminate chaos and bring order to multi‑team infrastructure projects.
