TERRAFORM-ASSOCIATE-003 practice question 1 of 30

[Understand Terraform Basics and CLI] If you update the version constraint in your Terraform configuration, Terraform will update your lock file the next time you run terraform Init.

Full set: 226 questions
Answer options
A: True
B: False
Correct Answer:
TRUE
Explanation

The .terraform.lock.hcl file records the specific versions of providers that Terraform has selected to use for a configuration. The terraform init command is responsible for initializing a working directory, which includes downloading and installing the necessary providers based on the version constraints defined in the configuration files. When terraform init is executed, it compares the version constraints in the configuration with the versions recorded in the lock file. If the constraints have been updated in a way that the locked version no longer satisfies them, Terraform will find the newest available provider version that meets the new constraint, download it, and update the .terraform.lock.hcl file to record the newly selected version and its checksum.

Why Incorrect

The "False" option is incorrect because it contradicts the fundamental dependency management workflow of Terraform. The primary mechanism for updating provider dependencies and the corresponding lock file is the terraform init command. If init did not update the lock file after a constraint change, the lock file would become outdated and no longer reflect the actual dependencies required by the configuration, defeating its purpose of ensuring consistent and repeatable builds.

References

1. HashiCorp Terraform Documentation, "Dependency Lock File (.terraform.lock.hcl)": In the section "Managing Selections in the Lock File," the documentation explicitly states: "If you change the version constraints for a provider in your configuration, the next time you run terraform init Terraform will select the newest-available provider version that meets the new constraint and update the lock file accordingly."

2. HashiCorp Terraform Documentation, "Command: init": Under the "Provider Installation" section, it describes the role of terraform init in downloading and installing providers. It notes, "If a lock file is present (.terraform.lock.hcl), terraform init will also check that the installed provider versions are consistent with the checksums recorded in the lock file..." This implies that init is the command that manages the relationship between the configuration, the installed providers, and the lock file.

3. HashiCorp Terraform Documentation, "Provider Requirements": This page details how to declare provider version constraints within the requiredproviders block. It establishes that these constraints are the source of truth that terraform init uses to select an appropriate provider version, which is then recorded in the lock file.

Scroll to Top