TF-Associate-004 - Terraform fundamentals - Section 2d

Explain how Terraform uses and manages state.

State maps configuration to real-world resources, records metadata and dependencies, and lets Terraform plan by comparing configuration against last-known state. Candidates should understand why state is authoritative for what Terraform manages and why it must not be hand-edited casually.

state as source of managed resourcesresource-to-real-world mappingstate metadataplan diff against state

Practice question for this objective

Free sampleTerraform fundamentalsmedium

An engineer imports an existing S3 bucket into Terraform, then runs terraform plan without changing the configuration. Terraform reports one attribute that differs from the configuration. Why can Terraform detect this difference at all?

terraform import aws_s3_bucket.assets my-existing-bucket
terraform plan
  • ABecause Terraform queries the provider's live API on every plan and never relies on stored data.
  • BBecause import also generates the matching resource block, so plan compares two generated files.
  • CBecause the import wrote a resource-to-real-world mapping into state, which plan then compares against the configuration. Correct
  • DBecause the S3 bucket stores its own Terraform metadata that plan reads back on each run.
Import populates the resource-to-real-world mapping in state, which plan diffs against configuration to detect drift. Terraform can only report a difference when it holds a mapping from a configuration address to a real resource; import creates that mapping in state, so a subsequent plan compares recorded attributes with the configuration and surfaces the mismatch.

Why A is wrong: Terraform does refresh against the provider, but the comparison that surfaces a diff is made between configuration and the mapping recorded in state, not the live API alone.

Why B is wrong: Classic import does not author the configuration block for you; the mapping lands in state and the practitioner still writes the HCL, so this misstates how import works.

Why C is correct: Import records the real bucket under the resource address in state, giving Terraform a stored mapping it can diff against the configuration to reveal the mismatched attribute.

Why D is wrong: Managed resources do not carry Terraform metadata in the cloud; the mapping and metadata that plan needs live in the state file, not on the bucket itself.

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

More in this domain

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

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