Terraform-Associate-004 practice question 34 of 35

As a developer, you want to ensure your plugins are up to date with the latest versions. Which Terraform command should you use?

Full set: 360 questions
Answer options
A: terraform refresh -upgrade
B: terraform apply -upgrade
C: terraform init -upgrade Correct answer
D: terraform providers -upgrade
Correct Answer:
C. terraform init -upgrade
Explanation

The terraform init command is used to initialize a working directory containing Terraform configuration files. This process includes downloading and installing the necessary provider plugins. To update these plugins to the latest versions allowed by the version constraints in your configuration, you must run terraform init with the -upgrade option. This tells Terraform to check for newer provider versions and install them if they are available and compatible.

Why Incorrect

A. terraform refresh updates the state file to match real-world infrastructure; it does not manage plugin versions and has no -upgrade option.
B. terraform apply creates, updates, or destroys infrastructure based on the configuration; it does not upgrade plugins and has no -upgrade option.
D. terraform providers is a command used to display information about providers required for the current configuration; it does not perform upgrades.

References

1. HashiCorp Terraform Documentation, "Command: init": Under the "Provider Installation" section, it states, "To upgrade to the latest acceptable version of all providers, run terraform init -upgrade." This command respects the version constraints defined in your configuration.

2. HashiCorp Terraform Documentation, "Provider Versioning": This page explains how Terraform handles provider versions and mentions that terraform init -upgrade is the command to use for upgrading to the latest compatible versions. It notes, "You can use the -upgrade option with terraform init to have Terraform consider newer versions than those already recorded in the dependency lock file."

Scroll to Top