0
0
Terraformcloud~10 mins

Root module concept in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Root module concept
Start Terraform Run
Load Root Module
Parse root main.tf
Load child modules if any
Evaluate variables and outputs
Plan and Apply Infrastructure
End
Terraform starts by loading the root module, which is the main folder with configuration files. It then processes any child modules, variables, and outputs before applying changes.
Execution Sample
Terraform
terraform {
  required_version = ">= 1.0"
}

resource "aws_s3_bucket" "example" {
  bucket = "my-example-bucket"
}
This code defines a root module with a single AWS S3 bucket resource.
Process Table
StepActionModule LoadedResource ProcessedVariables EvaluatedOutputs Evaluated
1Start Terraform runrootnonenonenone
2Parse root main.tfrootnonenonenone
3Process resource aws_s3_bucket.examplerootaws_s3_bucket.examplenonenone
4Evaluate variables (none defined)rootaws_s3_bucket.examplenonenone
5Evaluate outputs (none defined)rootaws_s3_bucket.examplenonenone
6Plan infrastructure changesrootaws_s3_bucket.examplenonenone
7Apply infrastructure changesrootaws_s3_bucket.examplenonenone
8End Terraform runrootaws_s3_bucket.examplenonenone
💡 Terraform finishes after applying all resources defined in the root module.
Status Tracker
VariableStartAfter Step 4Final
bucket_nameundefinedundefinedundefined
Key Moments - 3 Insights
Why does Terraform start with the root module?
Terraform always begins with the root module because it is the main folder containing the configuration files that define the infrastructure. This is shown in execution_table step 2 where the root main.tf is parsed first.
What happens if there are no variables defined in the root module?
If no variables are defined, Terraform simply skips variable evaluation as seen in execution_table step 4 where variables are 'none'. This means default or no values are used.
How does Terraform handle child modules in the root module?
Terraform loads child modules after parsing the root module. This is implied in the concept flow where after loading the root module, child modules are loaded before planning and applying.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the aws_s3_bucket resource processed?
AStep 3
BStep 2
CStep 5
DStep 7
💡 Hint
Check the 'Resource Processed' column in the execution_table rows.
According to the variable tracker, what is the value of 'bucket_name' after step 4?
Aempty string
Bundefined
Cmy-example-bucket
Dnull
💡 Hint
Look at the 'After Step 4' column for 'bucket_name' in variable_tracker.
If a child module was added, at which point in the concept flow would it be loaded?
ABefore starting Terraform run
BAfter applying infrastructure
CAfter loading root module
DAfter evaluating outputs
💡 Hint
Refer to the concept_flow ASCII diagram where child modules load after root module.
Concept Snapshot
Terraform Root Module:
- The root module is the main folder with Terraform files.
- Terraform starts by loading and parsing the root module.
- It processes resources, variables, and outputs here.
- Child modules are loaded after the root module.
- Terraform plans and applies infrastructure from the root module.
Full Transcript
Terraform uses the root module as the starting point for any infrastructure deployment. The root module is simply the folder where your main Terraform configuration files live. When you run Terraform, it first loads this root module, parses the configuration files like main.tf, and processes any resources defined there. If there are child modules referenced, Terraform loads those next. Then it evaluates variables and outputs before planning and applying the infrastructure changes. This flow ensures Terraform knows exactly what to create or change in your cloud environment starting from the root module.