HashiCorp Certified: Terraform Associate free question 4 / 10 · Domain 3: Core Terraform workflow
A working directory already has its child modules installed. The source of one module has new code available, and the team re-runs terraform init, but the installed copy stays the same. What does the init reference say to do?
- Run terraform init -reconfigure, which reinstalls the modules from scratch.
- Run terraform init -upgrade, which updates all modules to the latest source.
- Run terraform validate, which refreshes the installed copy of each module.
- Run terraform init -get=false, which forces the module sources to download.
Show the answer and explanation
Answer: B
Why this is correct
The "Child Module Installation" section says that during init the configuration is searched for module blocks, and the source code for referenced modules is retrieved from the locations in their source arguments. Re-running init with modules already installed will install the sources for any modules added to the configuration since the last init, but will not change any already-installed modules. To override this, use -upgrade, which updates all modules to the latest available source code. The General Options list describes -upgrade the same way, as opting to upgrade modules and plugins as part of their respective installation steps. A plain re-run therefore picks up new module blocks but leaves existing ones as they are.
Why the other options are wrong
"Run terraform init -get=false, which forces the module sources to download." … -get=false does the opposite: it skips child module installation. The reference recommends it only when the working directory was already previously initialized with its child modules.
"Run terraform init -reconfigure, which reinstalls the modules from scratch." … -reconfigure is a backend option of init that disregards any existing backend configuration. It is not part of child module installation.
"Run terraform validate, which refreshes the installed copy of each module." … Retrieving module source code from the locations in the source arguments is part of the Child Module Installation step of init, which is where new module blocks are installed.
Re-running init and modules
New module blocks: installed by a plain init. Modules already installed: left alone unless you add -upgrade.