1. An engineer runs `terraform init -upgrade` instead of `terraform init`. What is the effect of the `-upgrade` flag compared to a standard `terraform init`?
- A. It upgrades the Terraform CLI binary to the latest version available on the HashiCorp release server.
- B. It forces Terraform to ignore the `.terraform.lock.hcl` file entirely and select the latest provider version allowed by the version constraints, then updates the lock file.✓ Correct
- C. It re-initializes the backend and deletes all resources from state before re-downloading providers.
- D. It upgrades the Terraform state file schema to the latest format without modifying provider selections.
Explanation
Correct: B. The `-upgrade` flag tells `terraform init` to check for newer provider versions that still satisfy the version constraints in `required_providers`, rather than reusing the version already recorded in `.terraform.lock.hcl`. If a newer valid version is found, it downloads it and updates the lock file. This is how teams intentionally upgrade provider versions in a controlled way. A is wrong — `terraform init -upgrade` does NOT upgrade the Terraform CLI itself; CLI upgrades are done outside of Terraform (e.g., via package manager or manual download). C is wrong — `terraform init -upgrade` does not delete state or destroy resources; it only affects provider and module downloads. D is wrong — there is no `-upgrade` behavior related to state file schema migration; that happens automatically when Terraform reads a state file from an older format.