nerdexam
HashiCorp

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.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

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)
  • B
    7% (1)
  • C
    7% (1)
  • D
    87% (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.

Aterraform apply

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.

Bterraform plan

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.

Cterraform show

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.

Dterraform initCorrect

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

#Terraform CLI#terraform init#Workflow#Project Initialization

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice