004 · Domain 3: Core Terraform workflow · 13% of the exam
Task 3.2: Initialize a Terraform working directory
What terraform init does: backend set-up and state migration, module installation, provider installation and the lock file, the .terraform directory, and the options that change each step.
Study it
terraform init: backends, modules, providers and the .terraform directory
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
A team copies a configuration as the starting point for a new project. Its backend block still points at the old project's state, so the engineer edits the bucket name. terraform init now asks whether to copy the old state to the new location, which the engineer does not want. Which option starts with the new backend and leaves the old state alone?
Aterraform init -migrate-state
Bterraform init -reconfigure
Cterraform init -force-copy
Dterraform init -get=false
Show the answer and why
Aterraform init -migrate-state
Incorrect
-migrate-state copies the existing state to the new backend, the opposite of what is wanted.
Bterraform init -reconfigure
Correct
-reconfigure disregards the existing backend configuration and prevents migration of any existing state.
Cterraform init -force-copy
Incorrect
-force-copy answers yes to the migration prompts and implies -migrate-state.
Dterraform init -get=false
Incorrect
That skips child module installation and does not answer the migration question.
After a backend change, init needs either -migrate-state (bring the state along) or -reconfigure (start clean with the new settings).
A provider developer has built a local copy of a provider and wants one working directory to install providers only from the folder holding that build, just this once, without changing the CLI configuration. Which init option fits?
A-plugin-dir=PATH
B-from-module=PATH
C-backend-config=PATH
D-get=false
Show the answer and why
A-plugin-dir=PATH
Correct
-plugin-dir makes init read plugins only from the given directory, as a one-time override such as testing a local provider build.
B-from-module=PATH
Incorrect
-from-module copies a module into an empty directory; it does not choose where providers come from.
C-backend-config=PATH
Incorrect
That supplies backend settings.
D-get=false
Incorrect
That skips child module installation; providers are still installed normally.
For routine mirrors use the CLI configuration; -plugin-dir is the one-off override.