HashiCorp Terraform Associate (004) Question 60
Single answer3b Initialize a Terraform working directoryA platform engineer clones a Terraform configuration for an AWS application into a new workstation. The root module includes a required provider block for hashicorp/aws and a backend block configured for an existing remote backend. Before creating an execution plan, the engineer wants Terraform to download the required provider plugin, set up the backend, and prepare the working directory. Which command should the engineer run from the root of the configuration?
- A
terraform init
- B
terraform validate
- C
terraform plan
- D
terraform refresh
Show answer and explanation
Correct answer: A
Explanation
The correct answer is terraform init because initialization is required before most other Terraform workflow commands can run successfully in a new or changed working directory. In this scenario, the engineer needs three things that are specifically handled by initialization: backend initialization, provider plugin installation, and working directory preparation. According to Terraform CLI workflow best practices, terraform init is typically the first command run after cloning a configuration, after adding or changing providers, after configuring or changing a backend, or after adding child modules. terraform validate checks configuration correctness, while terraform plan evaluates proposed changes, but neither replaces initialization. HashiCorp documentation for the init command explicitly describes its role in initializing backend configuration, installing child modules, and installing provider plugins.
- A. Correct.
Correct.
terraform initinitializes the working directory by installing and configuring the backend, downloading required provider plugins, and preparing module and dependency data needed for later commands. This is the standard first step after cloning or creating a Terraform configuration. - B. Incorrect.
Incorrect.
terraform validatechecks whether the configuration is syntactically valid and internally consistent, but it does not perform full working directory initialization. It is not the command used to install providers and configure the backend as the first setup step. - C. Incorrect.
Incorrect.
terraform plancreates an execution plan, but it depends on the working directory already being initialized. If initialization has not been completed, Terraform will prompt the user to runterraform initfirst. - D. Incorrect.
Incorrect.
terraform refreshwas historically used to update state with real infrastructure information, but it is not the command for initializing a working directory. It does not prepare backend settings or install required providers for a newly cloned configuration.