Terraform-Associate-004 practice question 6 of 35

terraform init retrieves and caches the configuration for all remote modules.

Full set: 360 questions
Answer options
A: True
B: False
Correct Answer:
[TRUE]
Explanation

The terraform init command is responsible for preparing a working directory for use with Terraform. One of its primary tasks is module installation. During this process, Terraform scans the configuration for any module blocks that reference remote sources (such as the Terraform Registry, Git repositories, or HTTP URLs). It then downloads the source code for these modules and stores them in a local subdirectory named .terraform/modules. This local copy serves as a cache, ensuring that subsequent commands like plan and apply have access to the complete configuration code.

Why Incorrect

The statement is a correct description of a core function of the terraform init command. Therefore, selecting "False" would be incorrect. If terraform init did not retrieve and cache remote modules, Terraform would be unable to interpret the full configuration, and commands like terraform plan or terraform apply would fail because they would lack the resource definitions contained within those modules.

References

1. HashiCorp Terraform Documentation, "Command: init": In the "Module Installation" section, the documentation states, "During init, the root module's configuration is searched for module blocks, and the source code for referenced modules is retrieved from the locations given in their source arguments... Terraform will download and cache the module in a subdirectory of the .terraform/modules directory in your working directory."

Source: HashiCorp, Terraform CLI Documentation, "Command: init", section "Module Installation". Retrieved from https://developer.hashicorp.com/terraform/cli/commands/init#module-installation.

2. HashiCorp Terraform Documentation, "Module Sources": This page details how modules are sourced and explicitly links this action to the init command. It states, "When you run terraform init, Terraform will read the source argument for each of your modules and download the module's files into a subdirectory of your .terraform/modules directory."

Source: HashiCorp, Terraform Language Documentation, "Module Sources". Retrieved from https://developer.hashicorp.com/terraform/language/modules/sources#module-sources.

Scroll to Top