LinuxCommandLibrary

terraform-init

Initialize a Terraform working directory

TLDR

Initialize the current directory

$ terraform init
copy
Initialize and upgrade providers and modules
$ terraform init -upgrade
copy
Initialize with backend configuration from a file
$ terraform init -backend-config=[path/to/config.hcl]
copy
Initialize without configuring a backend
$ terraform init -backend=false
copy
Initialize and migrate state to a new backend
$ terraform init -migrate-state
copy
Initialize from a module source
$ terraform init -from-module=[source]
copy

SYNOPSIS

terraform init [options]

DESCRIPTION

terraform init initializes a working directory containing Terraform configuration files. This is the first command to run after writing a new configuration or cloning an existing one from version control. It is safe to run multiple times and will not delete existing configuration or state.
The command performs several initialization steps: it configures the backend for storing state, downloads and installs provider plugins declared in the configuration, and downloads child modules referenced in the configuration. Each of these steps can be individually controlled with flags.

PARAMETERS

-upgrade

Upgrade modules and plugins to the latest allowed versions.
-backend true|false
Enable or disable backend configuration. Default is true.
-backend-config path
Provide backend configuration via file path or key=value pair. Can be specified multiple times.
-reconfigure
Reconfigure the backend, ignoring any saved configuration. Prevents state migration.
-migrate-state
Attempt to copy existing state to the new backend with interactive prompts.
-force-copy
Suppress migration prompts and automatically copy state.
-from-module source
Copy a module into the target directory before initialization.
-get true|false
Download child modules. Default is true.
-plugin-dir path
Force plugin installation to read plugins only from the specified directory.
-lockfile mode
Set lockfile mode. Use readonly to verify checksums without updating the lockfile.
-input true|false
Enable or disable interactive prompts. Default is true.
-lock true|false
Lock state files during operations. Default is true.
-lock-timeout duration
Duration to retry acquiring a state lock. Default is 0s.
-no-color
Disable color codes in the output.
-json
Enable machine-readable JSON output.

CAVEATS

When changing backends, you must choose between -reconfigure (discard old state) and -migrate-state (copy state to new backend). Running init without either flag when the backend has changed will produce an error. The -plugin-dir option disables the default plugin download behavior, so the directory must contain all required providers.

HISTORY

Terraform was created by Mitchell Hashimoto and released by HashiCorp in 2014. The init command was introduced to manage the growing complexity of provider plugins and module dependencies. Provider plugin management was significantly reworked in Terraform 0.13 (2020) with the introduction of the dependency lock file and the public Terraform Registry as the default plugin source.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community