Why do we run 'terraform init' before 'terraform plan' when using Registry modules?
'terraform init' downloads the module code from the Registry so Terraform knows what resources to create. Without init, plan cannot evaluate the module. See execution_table step 2.
What happens if the module version is not specified?
Terraform uses the latest version available in the Registry by default. Specifying version ensures consistent infrastructure. This is shown in variable_tracker for module_version.
How does Terraform know what resources the module will create?
Terraform reads the module code downloaded during init, then uses inputs to plan resources. This is shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 2?
ATerraform reads the configuration file
BTerraform applies the infrastructure changes
CTerraform downloads the module code from the Registry
DTerraform creates the VPC resource
💡 Hint
Check execution_table row with Step 2 describing 'terraform init'
According to variable_tracker, what is the value of module_version after 'terraform init'?
A3.14.2
Bundefined
Clatest
Dmy-vpc
💡 Hint
Look at variable_tracker row for module_version under 'After init' column
If the module source was changed to a local path, how would the execution_table step 2 change?
ATerraform would download the module from the Registry
BTerraform would skip downloading and use local code
CTerraform would fail because source is invalid
DTerraform would apply the plan immediately
💡 Hint
Consider what 'terraform init' does when source is local instead of Registry
Concept Snapshot
Terraform Registry modules allow reuse of community or official modules.
Declare a module block with source and optional version.
Run 'terraform init' to download module code.
Run 'terraform plan' and 'apply' to create resources.
Specifying version ensures consistent deployments.
Modules simplify infrastructure management.
Full Transcript
Terraform Registry modules let you use pre-built infrastructure code. You write a module block in your Terraform config with a source pointing to the Registry module. Running 'terraform init' downloads the module code locally. Then 'terraform plan' reads the module inputs and shows what resources will be created. Finally, 'terraform apply' creates the resources in your cloud account. Specifying a version locks the module version for stability. This process helps you reuse tested infrastructure components easily.