TF-Associate-004 - Terraform state management - Section 6c

Configure remote state using the backend block.

A backend block inside terraform configures remote state (for example S3, or HCP Terraform via cloud), giving shared state and locking. Candidates should know changing the backend requires terraform init and that Terraform can migrate existing state.

backend blockremote stateshared state and lockingstate migration on init

Practice question for this objective

Free sampleTerraform state managementmedium

A practitioner wants to move an existing project from a local backend to HCP Terraform for remote state and remote runs. Which configuration block belongs inside the terraform block to connect the working directory to an HCP Terraform workspace?

terraform {
  # which block goes here?
}
  • AA backend "remote" block pointing at app.terraform.io, since that is the only supported way to reach HCP Terraform.
  • BA backend "cloud" block, because every remote integration is declared as a named backend.
  • CA cloud block naming the organisation and the workspace to use in HCP Terraform. Correct
  • DA provider "tfe" block configured with the organisation token and workspace name.
HCP Terraform is connected via the cloud block inside the terraform block, not a backend block. HCP Terraform integration is declared with a dedicated cloud block that names the organisation and workspace. It is distinct from a backend block, and it enables remote state storage and remote execution once init runs.

Why A is wrong: Tempting because the remote backend was the older approach and still works, but it is no longer the recommended way; the cloud block is the current integration.

Why B is wrong: Plausible by analogy with backend "s3", but there is no backend named cloud; HCP Terraform uses a top-level cloud block, not a backend block.

Why C is correct: Correct: HCP Terraform is configured with the cloud block, which names the organisation and workspace and enables remote state and runs after init.

Why D is wrong: This confuses managing HCP Terraform resources with connecting to it; the tfe provider manages settings via the API but does not wire state to a workspace.

See more TF-Associate-004 practice questions, answers explained.

More in this domain

Back to all Terraform state management objectives, or the TF-Associate-004 cert hub.

Examworthy is not affiliated with or endorsed by HashiCorp. Original, blueprint-aligned practice material only.