HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 147 of 223

Terraform Associate 004. Associate level, HashiCorp. Free question with the correct answer and a full explanation.

HashiCorp Terraform Associate (004) Question 147

Single answer5c Use modules in configuration

Your team maintains a reusable Terraform module named "network" in a private Git repository. A root configuration uses this module to create VPCs for multiple environments. After a teammate updates the module source code in the Git repo to add new subnet tags, you run terraform plan in the root configuration and notice the plan does not reflect the module changes. You want Terraform to download the updated module code without changing the module block itself. What should you do?

  1. A

    Run terraform get -update in the working directory to refresh downloaded modules

  2. B

    Run terraform init -upgrade in the working directory to reinitialize and upgrade modules

  3. C

    Run terraform refresh so Terraform reloads the module source before planning

  4. D

    Delete the state file so Terraform is forced to fetch the latest module source

Show answer and explanation

Correct answer: B

Explanation

Terraform modules are installed into the working directory during terraform init. When a module source is updated externally, Terraform does not automatically redownload it during terraform plan. To tell Terraform to revisit installed dependencies and retrieve newer acceptable versions or updated source content, use terraform init -upgrade. This is especially relevant when consuming modules from registries or version-controlled sources such as Git. In current Terraform usage, terraform init is the standard command for initializing and updating modules, while terraform refresh only reconciles state with real infrastructure and does not affect downloaded module code. Best practice is to manage module versions explicitly, often with version constraints for registry modules or stable Git references such as tags, so updates are intentional and repeatable.

  • A. Incorrect.

    Incorrect. terraform get was historically used to download and update modules, but modern Terraform workflows rely on terraform init for module installation and upgrades. On the Terraform Associate 004 exam, the expected current behavior is to use terraform init, not terraform get, to install or update modules in a working directory.

  • B. Correct.

    Correct. terraform init -upgrade tells Terraform to reinitialize the working directory and check for newer versions of installed providers and modules that match the configuration. This is the appropriate way to have Terraform redownload updated module source code when the module source has changed upstream but the module block in the root configuration has not changed.

  • C. Incorrect.

    Incorrect. terraform refresh updates state with information from real infrastructure. It does not reinstall or upgrade module source code from a registry, Git repository, or other module source location. A common misconception is to treat refresh as a general sync command, but it is for state and resource data, not module installation.

  • D. Incorrect.

    Incorrect. Deleting the state file is unnecessary and dangerous. Module source code is stored in the working directory's .terraform data, not in the state file. Removing state can orphan managed infrastructure and create drift or recreation risks. This option reflects a common but harmful troubleshooting mistake.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam