TF-004 Understand Terraform basics Practice Question
A company wants to use Terraform to create Azure resources. They have written a configuration file but when they run `terraform init`, they get a warning about an 'incomplete lock file'. What should they do first?
⚠ Common exam trap
A common pitfall in Terraform is assuming that `terraform plan` or `terraform validate` can repair lock file issues, when in fact only `terraform init` (or manual deletion of `.terraform.lock.hcl`) will resolve dependency tracking problems.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Delete the `.terraform.lock.hcl` and re-run `terraform init`
The warning about an 'incomplete lock file' indicates that the `.terraform.lock.hcl` file is corrupted, incomplete, or from an incompatible provider version. The correct first step is to delete the existing lock file and re-run `terraform init`, which will regenerate a fresh lock file based on the current configuration and provider requirements. This ensures dependency integrity before any planning or applying.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Change the provider version in the configuration
Why it's wrong here
Changing the `required_providers` block in your configuration to a different version constraint will not automatically resolve an existing issue with a corrupted or inconsistent `.terraform.lock.hcl` file. While it might prompt `terraform init` to update the lock file *if* `init` is run successfully afterward, simply modifying the configuration does not independently fix the integrity of the lock file itself or force its regeneration. The lock file's purpose is to record *specific* versions and their checksums, which requires `terraform init` to process.
- ✗
Run `terraform apply` immediately
Why it's wrong here
Running `terraform apply` without a successful `terraform init` will almost certainly fail because the working directory has not been properly prepared. `terraform init` is responsible for downloading the necessary provider plugins, configuring the backend, and setting up the `.terraform` directory. If the `.terraform.lock.hcl` file is problematic, `init` likely hasn't completed successfully, meaning `apply` would be unable to locate or initialize the required Azure provider to interact with the cloud.
- ✗
Run `terraform plan` to update the lock file
Why it's wrong here
`terraform plan` is designed to generate an execution plan by comparing the desired state in your configuration with the current state of your infrastructure. Its function is to show *what changes will be made*, not to manage provider installations or update the `.terraform.lock.hcl` file. The lock file is exclusively managed by `terraform init`, which resolves provider dependencies and records their cryptographic checksums.
- ✓
Delete the `.terraform.lock.hcl` and re-run `terraform init`
Why this is correct
The `.terraform.lock.hcl` file serves to pin the exact versions and cryptographic checksums of providers used in a configuration, ensuring consistent and reproducible deployments. If this file becomes corrupted, outdated, or inconsistent with the actual provider requirements, deleting it forces `terraform init` to perform a fresh resolution of all provider dependencies. Subsequently re-running `terraform init` will then download the appropriate providers and generate a new, accurate `.terraform.lock.hcl` file based on the current configuration's `required_providers` block.
- ✗
Run `terraform validate` to fix the warning
Why it's wrong here
`terraform validate` is used to check the syntax and internal consistency of your Terraform configuration files, ensuring they are syntactically correct and adhere to Terraform's language rules. It performs static analysis of the HCL code. However, `validate` does not interact with the provider installation process, download providers, or manage the `.terraform.lock.hcl` file. Therefore, it cannot resolve issues related to provider locking or initialization.
Go deeper
Related to this question
About these practice questions
One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.