TA-002-P · Question #439
You have just developed a new Terraform configuration for two virtual machines with a cloud provider. You would like to create the infrastructure for the first time. Which Terraform command should…
The correct answer is D. terraform init. Before any other Terraform workflow command can run against a new configuration, the working directory must be initialized with terraform init to download required provider plugins.
Question
You have just developed a new Terraform configuration for two virtual machines with a cloud provider. You would like to create the infrastructure for the first time. Which Terraform command should you run first?
Options
- Aterraform apply
- Bterraform plan
- Cterraform show
- Dterraform init
How the community answered
(15 responses)- B7% (1)
- C7% (1)
- D87% (13)
Why each option
Before any other Terraform workflow command can run against a new configuration, the working directory must be initialized with terraform init to download required provider plugins.
terraform apply attempts to create or modify infrastructure but will fail on a new configuration directory because the required provider plugins have not yet been downloaded.
terraform plan generates an execution plan showing what actions Terraform will take, but it also requires the working directory to be initialized first and cannot run before terraform init.
terraform show reads and outputs the current state file or a saved plan file, and has no role in the initial setup of a new configuration directory.
terraform init prepares the working directory by downloading provider plugins specified in the configuration, initializing the backend for state storage, and installing any required modules - none of the subsequent commands (plan, apply) can succeed until this step is complete.
Concept tested: Terraform workflow initialization with terraform init
Source: https://developer.hashicorp.com/terraform/cli/commands/init
Topics
Community Discussion
No community discussion yet for this question.