CertLumen

HashiCorp Terraform Associate (004) · Section 7 · 8% of the exam

Import existing infrastructure into your Terraform workspace

One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Maintain infrastructure with Terraform”. Here is what it covers, the points to remember and a question to try.

What it covers

Terraform only manages what is in its state. Import brings an object that already exists into state and under a resource block, either with a reviewable import block (the modern way) or the legacy terraform import command. This lesson covers both, generating starter configuration, and the checks that follow an import.

Points to remember

  • Terraform manages only what is in state; import adds an existing object to state without changing it
  • An import block has to (resource address) and id (provider-specific string known at plan time); identity is an alternative to id, never both
  • Import blocks are previewed by plan and applied by apply; apply reports 1 imported
  • terraform plan -generate-config-out=file writes best-guess HCL for targets without a resource block; the file must be new and the feature is experimental
  • The legacy terraform import ADDRESS ID changes state immediately, shows no preview and needs the resource block to exist

Try a question

An engineer imported the same cloud database under two different resource addresses so that two modules can both manage it. What is the risk?

  1. ATerraform merges both addresses into one state entry the next time it creates a plan for the whole configuration
  2. BTerraform refuses to save the state file at all as soon as two addresses share the same object ID
  3. CTerraform expects each remote object to be bound to one address, so changes or a destroy from one can break the other
  4. DThe second import fails with an error, so only the first address is ever tracked in the state file of the root module
Show the answer

C. The import documentation warns that Terraform expects each remote object to be bound to only one resource address. Binding it twice leads to unwanted behavior, for example one address destroying an object that the other still relies on. Use terraform state list -id= before importing to check.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Importing existing infrastructure teaches this objective (about 40 minutes), and 16 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 37 objectives · Next objective →