This article walks through how to use the Terraform Cloud backend (the cloud block) to cleanly connect workspaces to your codebase, organized around the topics that Associate and Pro level exams tend to test.
We make concrete the points that often cause confusion in both exams and real-world operations: how it differs from local and S3 backends, when to choose CLI vs VCS driven workflows, variable and permission best practices, and what to check when things go wrong.
The Terraform Cloud backend handles state storage and locking, run history, policy enforcement, and RBAC on the service side. Compared with the local backend, it reduces concurrent-run conflicts and the toil of distributing state, while improving auditability.
The smallest unit in Terraform Cloud is the workspace. Think of one workspace as one state, and bind your codebase (directory) to a workspace. Explicitly specifying the organization and target workspace name in the cloud block prevents accidents where apply lands on the wrong state.
The pattern with the fewest collisions is to pin cloud.workspaces.name per directory (stack). This way terraform apply always targets the same workspace, and you avoid unintended state overwrites.
Terraform Cloud runs execute with the Terraform version configured on the workspace. The local CLI just submits jobs. Differences between local and service versions usually work, but to avoid parse errors caused by language feature differences, do not let them drift too far apart.
Example of the cloud block, remote execution, and remote state referencing
# terraform/main.tf
terraform {
cloud {
organization = "acme"
workspaces {
name = "network-prod"
}
# When using TFE:
# hostname = "tfe.example.com"
}
# The Terraform CLI submits the job. The run executes with the version configured on the workspace.
}
provider "aws" {
region = var.region
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "core-prod"
cidr = "10.0.0.0/16"
}
# Safely reference another workspace's state (read-only)
data "terraform_remote_state" "shared" {
backend = "remote"
config = {
organization = "acme"
workspaces = {
name = "shared-services-prod"
}
}
}
output "shared_vpc_id" {
value = data.terraform_remote_state.shared.outputs.vpc_id
}
To reduce misapplies, split workspaces along environment, region, and product axes. Sizing each workspace by the unit of change keeps maintenance easy and improves plan visibility.
In monorepo setups, aligning your directory structure with your workspace naming convention makes VCS-driven auto-trigger configuration much easier.
Terraform Cloud has workspace variables (Terraform variables and environment variables) plus Variable Sets that span organizations or projects. Putting common values in a Variable Set and per-workspace differences in the workspace itself keeps things simple.
Register sensitive values as Sensitive and, as a rule, never put them in .tfvars or VCS. Mark provider authentication environment variables (e.g. AWS_ACCESS_KEY_ID) as Sensitive too.
Terraform Cloud lets you control workspace operations via team and user permissions. Splitting at a granularity such as "can view plan but cannot apply" suppresses operator error.
By inserting policies (Sentinel) and Run Tasks (security/cost check integrations), you can automatically validate organizational standards before apply.
For CLI-driven runs, the token in ~/.terraform.d/credentials.tfrc.json created by terraform login is used. Plan and apply execute remotely with the Terraform version and execution mode configured on the workspace, and logs are streamed back.
Common failures include workspace name mismatches, bad or missing auth tokens, unset provider authentication environment variables, and syntax errors from version mismatches. Checking the init output, the Remote Runs job log, and the Variables screen first is the fastest way to triage.
| Item | Terraform Cloud backend | S3 backend | Local backend |
|---|---|---|---|
| State storage / locking | Automatic locking and version management on the service side | Separate DynamoDB-based locking design and bucket permission management | No locking, manual distribution required |
| Execution / auditing | Remote execution, queue/approval, log/history/diff persistence | Local execution by default; auditing supplemented externally | Fully local; auditing and history are on you |
| Permissions / RBAC | Fine-grained control via workspace/team permissions | Effectively handled with S3/IAM plus operational rules | Depends on machine access rights |
| Policy / integration | Sentinel, Run Tasks, and Cost Estimation integration | Supplemented with external tool integrations | Assumes external tools |
| Setup ease | Quick to introduce with the cloud block | Requires S3/DynamoDB/encryption/AWS design | Minimal, but high operational burden for team use |
CLI-driven execution flow (Terraform Cloud backend)
[Dev Laptop]
|
| terraform plan/apply (CLI submits run)
v
[Terraform Cloud Workspace]
| (remote plan/apply, state lock/versioning)
v
[Providers/Cloud APIs]
|
v
[Managed Resources]
State path: Managed in Terraform Cloud (per workspace)
Logs/Policies: Stored/enforced in Terraform CloudAssociate / Pro
問題 1
In a CLI-driven workflow that specifies workspaces.name in the Terraform Cloud cloud block, which practice most reduces the risk of applying to the wrong workspace?
正解: A
With the Cloud backend, fixing one directory to one workspace is the safest. The local terraform workspace command is not the mechanism for switching Cloud workspaces, and relying on environment variables or interactive selection increases human error.
What is the difference between the cloud block and the legacy remote backend?
The cloud block is the recommended, concise way to integrate with Terraform Cloud / TFE. It provides the same remote state and remote execution as the legacy backend "remote", but the way you specify organization and hostname is clearer, and it is designed to evolve with future feature additions.
Should the Terraform version match the local CLI or Terraform Cloud?
Runs execute with the Terraform version configured on the workspace. The local CLI mostly just submits the job, but an extremely old or new local CLI can fail on syntax or plugin resolution, so it is safest to use a stable version close to the one the workspace uses.
What is the safe way to reference outputs from another workspace?
Use data "terraform_remote_state" and read the target read-only by explicitly specifying the organization and workspaces.name. Avoid downloading state files directly or distributing them manually, and keep the set of producers and consumers as small as possible.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
HCL Syntax: Terraform's Configuration Language (2026)
HCL2 fundamentals for Terraform — blocks, attributes, expres...
Terraform Authoring & Operations Pro: Complete Guide (2026)
Tactics for the Terraform Pro exam — module authoring, works...
Terraform Providers: Plugin Management Fundamentals (2026)
Provider mechanics — required_providers, versions, mirrors, ...
Terraform Resource Blocks: Declarative Infra Units (2026)
Resource block fundamentals — addresses, references, common ...
Terraform Data Sources: Read-Only External Data (2026)
Data source basics — declaration, refresh behavior, dependen...