Terraform Associate 004 ยท Core Terraform workflow
terraform init
What init does: providers, modules, backend setup, .terraform directory, when to rerun, -upgrade, -reconfigure, -migrate-state at a glance (3b).
Key points
- Prepares a working directory: configures the backend, installs child modules from module blocks, and installs the provider plugins the configuration needs.
- Run it first after writing or cloning a configuration and again after changing backend settings or adding modules.
- It is safe to repeat and never deletes your configuration or state.
- Useful flags: -upgrade, -reconfigure, -migrate-state.
Source: https://developer.hashicorp.com/terraform/cli/commands/init
Practice questions
Which set of tasks does terraform init perform?
- Configures the backend, installs modules, installs providers
- Creates resources, updates state, prints outputs
- Formats files, validates syntax, removes unused variables
- Locks the workspace, destroys drift, uploads state
Show answer
Answer: A. Configures the backend, installs modules, installs providers
init sets up the backend, fetches child modules, and installs provider plugins. Creating resources is apply's job.
In which situations should you rerun terraform init?
- You added a new module block
- You changed the backend settings
- You changed a tag value on an existing resource
- You want newer provider versions allowed by your constraints
- You changed the value of an output
Show answer
Answer: A. You added a new module block, B. You changed the backend settings, D. You want newer provider versions allowed by your constraints
New modules, backend changes, and provider upgrades (with -upgrade) all need init. Editing a tag value or an output does not touch plugins, modules, or the backend.
Running terraform init again in a directory that already has state will erase that state.
Show answer
Answer: False
False. init never deletes your configuration or state, so repeating it is safe.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
