Plain language
terraform init prepares a directory so Terraform can work in it. It doesn't create any infrastructure.
Under the hood
init performs up to four tasks:
- Backend initialization. Configures where state is stored (local by default; remote in Module 6).
- Module installation. Downloads child modules into
.terraform/modules/. - Provider installation. Downloads providers into
.terraform/providers/, honoring the lock file (Module 2). - Lock file. Creates or updates
.terraform.lock.hcl.
init is safe to re-run. It never touches infrastructure or modifies resources in state.
Re-run init when you:
- Clone a repo or start in a new directory
- Add or change a provider requirement
- Add a module, or change a module's
sourceorversion - Add or change a backend or
cloudblock
You don't need to re-run it after changing resource arguments, variables, or outputs.
| Flag | Purpose |
|---|---|
-upgrade |
Re-select the newest allowed provider and module versions |
-backend=false |
Skip backend initialization (for example, to validate in CI without credentials) |
-backend-config=... |
Supply partial backend settings (Module 6) |
-migrate-state / -reconfigure |
Move state to a new backend, or ignore the existing backend configuration (Module 6) |
-input=false |
Fail rather than prompt. Use this in automation. |