HCP Terraform workspaces and runs
What HCP Terraform adds to the CLI
HCP Terraform is a hosted collaboration and execution service for Terraform. A team can keep state in a shared location, coordinate runs, review proposed changes and share reusable modules. Terraform CLI remains the tool that evaluates configurations and interacts with providers. A hosted workspace represents a managed collection of configuration, settings, variables and state; a CLI workspace is primarily a named state selection within one working directory. They are not interchangeable. An object storage backend can store state without supplying the hosted run workflow.
Trace a run from configuration to approval
Imagine a bookstore catalog team that reviews an infrastructure change before applying it. A run associates a configuration version with a workspace. A plan describes proposed operations; approval, if required, is a separate step. The example is a simplified educational record, not an actual HCP API response or status vocabulary.
Fictional run: R-17 / catalog-test / commit c17Configuration selected -> plan queued -> plan reviewedExpected changes: 1 add, 0 updates, 0 deletesApply approval: pendingDecision: wait; no infrastructure change authorizedOne new resource is proposed, not created. In a plan-only or speculative run there is no apply phase. In a standard run, the selected workflow, permissions, policy outcomes and auto-apply settings determine whether confirmation is required. Do not equate a successful plan with an authorized apply. After applying, inspect the outcome and verify the application independently.
Choose the workflow and execution location separately
A workflow determines how a run begins. VCS-driven workflows receive changes from a connected repository; pull request plans can provide feedback without applying. CLI-driven workflows use familiar commands to initiate runs; API-driven workflows let authorized automation upload a configuration version and request a run. Execution mode determines where Terraform operates: remote mode uses hosted workers, agent mode uses configured agents, and local mode executes on the workstation while retaining managed state. Agent availability depends on the service edition and configuration. This simplified comparison is not a feature entitlement matrix.
Workflow InitiatorVCS Reviewed repository changeCLI Authorized operator commandAPI Authorized automation request
Execution Terraform process locationRemote Hosted workerAgent Configured agent environmentLocal Operator workstationA CLI command in remote mode is an external operation, not a local simulation. A local mode workspace does not evaluate hosted workspace variables or variable sets for the local process. Provider credentials and inputs must instead be provided to the local execution environment through approved mechanisms.
Read a cloud block without connecting
The cloud block links a root module to HCP Terraform. The following is a static illustration using invented organization and workspace names. The project argument requires a compatible CLI; the inherited provisional baseline is not tested. Do not save this as an active configuration or initialize it.
terraform { required_version = "= 1.14.8" cloud { organization = "fictional-meadow-labs" workspaces { name = "catalog-dev" project = "storefront" } }}Initialization may contact HCP Terraform, create a workspace if the selected configuration permits it, and prompt for state migration. Login, VCS connection, workspace creation and any remote plan require separate authorization. Do not combine a cloud block and an ordinary backend block in one root configuration. Check workspace ownership and execution mode before running commands.
Practice with a provider-download-free local configuration
Use only the supplied local fixture in an empty approved lab directory, with no cloud block or remote backend. The example models a service name, not a hosted run.
terraform { required_version = "= 1.14.8"}
variable "environment" { type = string default = "dev"}
resource "terraform_data" "catalog" { input = "catalog-${var.environment}"}
output "service_name" { value = terraform_data.catalog.input}On the provisional CLI, after verifying the directory and tool provenance, the intended local workflow is terraform init, terraform validate, and terraform plan. Expect a proposed local terraform_data instance and output catalog-dev; no cloud objects. Native execution has not been performed. No apply is necessary for this exercise. Do not infer HCP integration support from local success.
Avoid the common run-review mistakes
A speculative plan is not a reusable approval for a different configuration version. A queued run is not proof of an apply. A remote plan can read provider APIs and sensitive inputs even when it does not apply. If the run target, source commit, policy result or approval identity is uncertain, hold the change. Inspect state versions only with authorized access, because they may contain sensitive values. Learn to distinguish a run history entry from a state version and from an actual provider-side object.
Practice and next step
Complete the fictional run decision worksheet and explain the difference between workflow and execution mode. Then move to project organization, variable sets and collaboration. Reference: terraform-concept-hcp-terraform-workspaces-and-runs. Official documentation: https://developer.hashicorp.com/terraform/cloud-docs/workspaces and https://developer.hashicorp.com/terraform/cloud-docs/workspaces/run/modes-and-options.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HCP Terraform workspaces and runs — knowledge check
Review hosted run and collaboration decisions.
What is an HCP Terraform workspace?
What does a plan-only run authorize?
Where does agent execution run?
What might initialization with a cloud block do?
What is the difference between a VCS workflow and remote execution?