Bitzu

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

Single choice

Which set of tasks does terraform init perform?

  1. Configures the backend, installs modules, installs providers
  2. Creates resources, updates state, prints outputs
  3. Formats files, validates syntax, removes unused variables
  4. 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.

Select all that apply

In which situations should you rerun terraform init?

  1. You added a new module block
  2. You changed the backend settings
  3. You changed a tag value on an existing resource
  4. You want newer provider versions allowed by your constraints
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module