TA-002-P · Question #80
You write a new Terraform configuration and immediately run terraform apply in the CLI using the local backend. Why will the apply fail?
The correct answer is B. Terraform needs to install the necessary plugins first. A terraform apply command will fail in a new configuration with a local backend because Terraform needs to first install the necessary provider plugins during the terraform init phase. Without initialization, Terraform cannot interact with the specified infrastructure providers.
Question
You write a new Terraform configuration and immediately run terraform apply in the CLI using the local backend. Why will the apply fail?
Options
- ATerraform needs you to format your code according to best practices first
- BTerraform needs to install the necessary plugins first
- CThe Terraform CLI needs you to log into Terraform cloud first
- DTerraform requires you to manually run terraform plan first
How the community answered
(57 responses)- A11% (6)
- B82% (47)
- C2% (1)
- D5% (3)
Why each option
A `terraform apply` command will fail in a new configuration with a local backend because Terraform needs to first install the necessary provider plugins during the `terraform init` phase. Without initialization, Terraform cannot interact with the specified infrastructure providers.
Code formatting (e.g., via `terraform fmt`) is for readability and consistency, not a prerequisite for `terraform apply` to succeed.
When a new Terraform configuration is created, `terraform init` must be run first to download and install the required provider plugins and modules. Without these plugins, `terraform apply` cannot understand or interact with the resources defined in the configuration.
Logging into Terraform Cloud is only required if using Terraform Cloud as a backend or for remote operations, not for a local backend.
While `terraform plan` is a good practice to review changes, it is not strictly required before `terraform apply`; `apply` implicitly performs a plan.
Concept tested: Terraform initialization and provider plugin installation
Source: https://developer.hashicorp.com/terraform/cli/commands/init
Topics
Community Discussion
No community discussion yet for this question.