What an HCP Terraform workspace contains
| Component | Notes |
|---|---|
| State | Plus state version history. You can view earlier versions and roll back. |
| Variables | Terraform and environment variables, optionally marked sensitive |
| Run history | Every plan and apply, with logs, who triggered it, and the outcome |
| Settings | Terraform version, execution mode, working directory, auto-apply, VCS connection, notifications |
| Permissions | Team access levels |
| Policies and run tasks | Inherited from policy sets and run-task configuration |
| Locking | Automatic during runs, plus a manual lock in the UI |
HCP Terraform workspaces vs. CLI workspaces
| CLI workspace | HCP Terraform workspace | |
|---|---|---|
| Unit | An extra named state in one backend | A full working environment |
| Variables | Shared configuration and tfvars | Per-workspace, plus variable sets |
| Access control | None of its own | Per workspace or project, by team |
| Run history and audit | None | Yes |
| Typical mapping | Temporary copies of one environment | One workspace per environment per component, such as network-prod and app-dev |
Organizing work
- Split by component and environment. Use workspaces like
network-prodandapp-prodinstead of one large workspace. Smaller states mean faster runs, smaller blast radius, and clearer ownership. - Group with projects. For example, a
paymentsproject holds thepayments-*workspaces, and the payments team gets project-level access. - Share outputs between workspaces with the
tfe_outputsdata source from thetfeprovider, or withterraform_remote_stateif the workspace's remote state sharing settings allow it. HashiCorp recommendstfe_outputs, because it exposes outputs only.
data "tfe_outputs" "network" {
organization = "acme"
workspace = "network-prod"
}
# data.tfe_outputs.network.values.vpc_id (values are marked sensitive)
# data.tfe_outputs.network.nonsensitive_values.vpc_id- Run triggers connect workspaces, so that a successful apply in
network-prodautomatically queues a run inapp-prod.