Bird
Raised Fist0
Terraformcloud~20 mins

Root module concept in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Terraform Root Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the root module in Terraform?

In Terraform, what does the term root module refer to?

AA module that is automatically created by Terraform for each provider.
BA special Terraform module that manages remote state storage.
CThe directory where Terraform configuration files are loaded and executed by default.
DA module that contains only variables and no resources.
Attempts:
2 left
💡 Hint

Think about where Terraform starts reading your configuration files.

❓ Architecture
intermediate
2:00remaining
How does Terraform handle nested modules called from the root module?

When a root module calls a child module, how does Terraform treat the child module?

AAs a separate module with its own state, isolated from the root module.
BAs part of the root module's configuration and state, but logically separated.
CAs a completely independent Terraform project requiring separate initialization.
DAs a provider plugin that manages resources automatically.
Attempts:
2 left
💡 Hint

Consider how Terraform manages state for modules called inside other modules.

❓ Configuration
advanced
2:00remaining
What is the output of this Terraform root module configuration?

Given this root module code snippet, what will be the value of the output instance_name?

Terraform
module "web_server" {
  source = "./modules/server"
  name   = "app-server"
}

output "instance_name" {
  value = module.web_server.name
}
A"app-server"
B"web_server"
Cnull
DSyntaxError: output value must be a string
Attempts:
2 left
💡 Hint

Look at how the module input name is passed and then output is referencing it.

❓ security
advanced
2:00remaining
Which practice improves security when using root modules in Terraform?

When managing sensitive data in a root module, which practice is best to keep secrets safe?

AHardcoding secrets directly in the root module variables.tf file.
BIncluding secrets in output blocks to easily access them after deployment.
CStoring secrets in plain text files inside the root module directory.
DUsing environment variables or secret management tools to inject sensitive values.
Attempts:
2 left
💡 Hint

Think about how to avoid exposing secrets in code or outputs.

❓ service_behavior
expert
2:00remaining
What happens if the root module's Terraform state file is deleted accidentally?

If the Terraform state file for the root module is deleted, what is the expected behavior when running terraform apply again?

ATerraform will recreate all resources because it thinks none exist.
BTerraform will detect existing resources and import them automatically without changes.
CTerraform will fail with an error saying state file is missing and stop execution.
DTerraform will ignore the missing state and only update resources defined in child modules.
Attempts:
2 left
💡 Hint

Consider how Terraform uses the state file to track resources.

Practice

(1/5)
1. What is the root module in Terraform?
easy
A. A Terraform provider plugin
B. A special Terraform resource type
C. A remote backend configuration
D. The main folder where Terraform commands are run and resources are defined

Solution

  1. Step 1: Understand the root module role

    The root module is the main folder where you write your Terraform code and run commands.
  2. Step 2: Differentiate from other concepts

    It is not a resource type, backend, or provider plugin but the main working directory.
  3. Final Answer:

    The main folder where Terraform commands are run and resources are defined -> Option D
  4. Quick Check:

    Root module = main Terraform folder [OK]
Hint: Root module is your main Terraform folder [OK]
Common Mistakes:
  • Confusing root module with provider or backend
  • Thinking root module is a resource type
  • Assuming root module is a plugin
2. Which command must be run inside the root module folder to initialize Terraform?
easy
A. terraform apply
B. terraform init
C. terraform plan
D. terraform validate

Solution

  1. Step 1: Identify the initialization command

    terraform init sets up the working directory by downloading providers and preparing the backend.
  2. Step 2: Confirm command location

    This command must be run inside the root module folder where the Terraform files exist.
  3. Final Answer:

    terraform init -> Option B
  4. Quick Check:

    Initialize Terraform = terraform init [OK]
Hint: Use 'terraform init' to start in root module folder [OK]
Common Mistakes:
  • Running terraform apply before init
  • Confusing init with plan or validate
  • Running commands outside root module folder
3. Given this root module folder structure:
root-module/
  main.tf
  variables.tf
  modules/
    network/
      main.tf
Which statement is true about the root module?
medium
A. It can call the network module inside the modules folder
B. It must be empty to work correctly
C. It cannot use modules from subfolders
D. It only contains variables and no resources

Solution

  1. Step 1: Understand root module and submodules

    The root module can call other modules located in subfolders like modules/network.
  2. Step 2: Evaluate options

    It can call the network module inside the modules folder correctly states the root module can call the network module. Other options are false.
  3. Final Answer:

    It can call the network module inside the modules folder -> Option A
  4. Quick Check:

    Root module calls submodules = true [OK]
Hint: Root module can call modules in subfolders [OK]
Common Mistakes:
  • Thinking root module cannot use submodules
  • Assuming root module must be empty
  • Believing root module only has variables
4. You run terraform apply in your root module folder but get an error: "No configuration files found". What is the likely cause?
medium
A. You ran the command outside the root module folder
B. You forgot to run terraform init first
C. Your Terraform version is outdated
D. You have no internet connection

Solution

  1. Step 1: Analyze the error message

    "No configuration files found" means Terraform cannot find .tf files in the current folder.
  2. Step 2: Identify common cause

    This usually happens if you run terraform apply outside the root module folder where the files exist.
  3. Final Answer:

    You ran the command outside the root module folder -> Option A
  4. Quick Check:

    Run commands inside root module folder [OK]
Hint: Run commands inside root module folder with .tf files [OK]
Common Mistakes:
  • Assuming init missing causes this error
  • Blaming Terraform version or internet
  • Not checking current folder location
5. You want to organize your Terraform project with a root module that calls two child modules: network and compute. Which folder structure and root module code is correct?
hard
A.
root/
  main.tf
  network.tf
  compute.tf

# main.tf does not call modules
B.
root/
  network/
    main.tf
  compute/
    main.tf

# main.tf calls modules from root folder
C.
root/
  main.tf
  modules/
    network/
      main.tf
    compute/
      main.tf

# main.tf calls both modules with module blocks
D.
root/
  main.tf
  modules/
    network/
      main.tf
    compute/
      main.tf

# main.tf does not call any modules

Solution

  1. Step 1: Understand proper module folder structure

    Child modules should be inside a modules folder under root for clarity and best practice.
  2. Step 2: Confirm root module calls child modules

    The root module's main.tf must include module blocks to call network and compute modules.
  3. Final Answer:

    Folder with modules subfolder and main.tf calling modules -> Option C
  4. Quick Check:

    Root calls modules in modules/ folder [OK]
Hint: Put child modules in modules/ and call them in root main.tf [OK]
Common Mistakes:
  • Placing modules outside modules/ folder
  • Not calling modules in root main.tf
  • Confusing separate folders as root module
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard