If you add a new resource using the same provider and do not update the version constraint, and a lock file exists, which version will Terraform use?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

If you add a new resource using the same provider and do not update the version constraint, and a lock file exists, which version will Terraform use?

Explanation:
Terraform pins the exact provider versions with a lock file to ensure reproducible runs. When you add a new resource with the same provider and you don’t change the version constraint, Terraform will install and use the exact version recorded in the lock file. That lock file reflects the version that was resolved and installed during the last terraform init, so it governs all subsequent operations for consistency across resources, not the latest available version. The state file tracks resources and their attributes, not which provider version to use for new resources. If you want to upgrade to a newer provider version, you’d need to update the constraint and refresh the lock file (for example, with an init -upgrade).

Terraform pins the exact provider versions with a lock file to ensure reproducible runs. When you add a new resource with the same provider and you don’t change the version constraint, Terraform will install and use the exact version recorded in the lock file. That lock file reflects the version that was resolved and installed during the last terraform init, so it governs all subsequent operations for consistency across resources, not the latest available version.

The state file tracks resources and their attributes, not which provider version to use for new resources. If you want to upgrade to a newer provider version, you’d need to update the constraint and refresh the lock file (for example, with an init -upgrade).

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy