github.com/hugorut/terraform@v1.1.3/website/docs/cli/init/index.mdx (about) 1 --- 2 page_title: Initializing Working Directories - Terraform CLI 3 description: >- 4 Working directories contain configurations, settings, cached plugins and 5 modules, and state data. Learn how to initialize and manage working 6 directories. 7 --- 8 9 # Initializing Working Directories 10 11 Terraform expects to be invoked from a working directory that contains 12 configuration files written in 13 [the Terraform language](/language). Terraform uses 14 configuration content from this directory, and also uses the directory to store 15 settings, cached plugins and modules, and sometimes state data. 16 17 A working directory must be initialized before Terraform can perform any 18 operations in it (like provisioning infrastructure or modifying state). 19 20 ## Working Directory Contents 21 22 A Terraform working directory typically contains: 23 24 - A Terraform configuration describing resources Terraform should manage. This 25 configuration is expected to change over time. 26 - A hidden `.terraform` directory, which Terraform uses to manage cached 27 provider plugins and modules, record which 28 [workspace](/cli/workspaces) is currently active, and 29 record the last known backend configuration in case it needs to migrate state 30 on the next run. This directory is automatically managed by Terraform, and is 31 created during initialization. 32 - State data, if the configuration uses the default `local` backend. This is 33 managed by Terraform in a `terraform.tfstate` file (if the directory only uses 34 the default workspace) or a `terraform.tfstate.d` directory (if the directory 35 uses multiple workspaces). 36 37 ## Initialization 38 39 Run the `terraform init` command to initialize a working directory that contains 40 a Terraform configuration. After initialization, you will be able to perform 41 other commands, like `terraform plan` and `terraform apply`. 42 43 If you try to run a command that relies on initialization without first 44 initializing, the command will fail with an error and explain that you need to 45 run init. 46 47 Initialization performs several tasks to prepare a directory, including 48 accessing state in the configured backend, downloading and installing provider 49 plugins, and downloading modules. Under some conditions (usually when changing 50 from one backend to another), it might ask the user for guidance or 51 confirmation. 52 53 For details, see [the `terraform init` command](/cli/commands/init). 54 55 ## Reinitialization 56 57 Certain types of changes to a Terraform configuration can require 58 reinitialization before normal operations can continue. This includes changes to 59 provider requirements, module sources or version constraints, and backend 60 configurations. 61 62 You can reinitialize a directory by running `terraform init` again. In fact, you 63 can reinitialize at any time; the init command is idempotent, and will have no 64 effect if no changes are required. 65 66 If reinitialization is required, any commands that rely on initialization will 67 fail with an error and tell you so. 68 69 ## Reinitializing Only Modules 70 71 The `terraform get` command will download modules referenced in the 72 configuration, but will not perform the other required initialization tasks. 73 This command is only useful for niche workflows, and most Terraform users can 74 ignore it in favor of `terraform init`.