Discover how Terraform chooses the provider version when adding a new resource to an existing configuration with a .terraform-lock.hcl file present.
Table of Contents
Question
You add a new resource to an existing Terraform configuration, but do not update the version constraint in the configuration. The existing and new resources use the same provider. The working directory contains a .terraform-lock.hcl file.
How will Terraform choose which version of the provider to use?
A. Terraform will use the latest version of the provider for the new resource and the version recorded in the lock file to manage existing resources
B. Terraform will use the version recorded in your lock file
C. Terraform will check your state file to determine the provider version to use
D. Terraform will use the latest version of the provider available at the time you provision your new resource
Answer
B. Terraform will use the version recorded in your lock file
Explanation
When you add a new resource to an existing Terraform configuration that already has a .terraform-lock.hcl file, Terraform will use the provider version specified in the lock file for both the existing and new resources. The lock file ensures consistent provider versions across the entire configuration, even when new resources are introduced. This approach maintains compatibility and prevents potential issues that could arise from using different provider versions within the same configuration.
HashiCorp Certified: Terraform Associate certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the HashiCorp Certified: Terraform Associate exam and earn HashiCorp Certified: Terraform Associate certification.