terraform init
The command that prepares a directory for Terraform: it downloads providers, fetches modules, connects the backend and writes the lock file.
In more detail
It never creates or changes infrastructure, so it is safe to run at any time and nearly instant on a prepared directory. Run it after cloning and whenever providers, version constraints, module calls or the backend change, including when you pull someone else's change to them. Other commands refuse to run and tell you to initialise when they detect it is needed.
Examples
terraform initterraform init -input=falseRelated terms
- .terraform directory — The hidden folder terraform init creates beside your configuration, holding downloaded providers, fetched modules and backend settings.
- dependency lock file — The .terraform.lock.hcl file that terraform init writes to record the exact provider versions chosen and their checksums.
- Terraform backend — The setting that decides where Terraform stores state and how it locks it, from a local file to shared cloud storage.
- terraform init -upgrade — The init option that ignores the versions in the lock file and picks the newest provider and module versions the constraints still allow.
Taught in
- What Is Infrastructure As Code? — Infrastructure as Code with Terraform
- Installing Terraform And Meeting The CLI — Infrastructure as Code with Terraform
- Providers And The required_providers Block — Infrastructure as Code with Terraform
- Initialising The Working Directory — Infrastructure as Code with Terraform
- Calling Your Module And Passing Variables — Infrastructure as Code with Terraform
- Running Terraform In CI — Infrastructure as Code with Terraform
- Native Testing With Tftest Files — Infrastructure as Code with Terraform
- Provider Mocking For Tests — Infrastructure as Code with Terraform
- Policy As Code With OPA — Infrastructure as Code with Terraform
- Releasing The Real Cloud Artifact — Infrastructure as Code with Terraform
- Providers: How Terraform Reaches Every API — HashiCorp Terraform Associate (004) Exam Prep
- Versions, The Lock File And Provider Aliases — HashiCorp Terraform Associate (004) Exam Prep
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Sensitive Data, Ephemeral Values And Secrets From Vault — HashiCorp Terraform Associate (004) Exam Prep
- Where Modules Come From — HashiCorp Terraform Associate (004) Exam Prep