0
0
Terraformcloud~20 mins

Test file structure in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform File Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Identify the correct Terraform file structure for a multi-environment setup

You want to organize Terraform files for two environments: dev and prod. Which file structure below correctly separates environment-specific configurations while sharing common resources?

Aroot/main.tf, root/variables.tf, root/dev/main.tf, root/prod/main.tf
Broot/main.tf, root/variables.tf, root/environments/dev.tf, root/environments/prod.tf
Croot/dev/main.tf, root/dev/variables.tf, root/prod/main.tf, root/prod/variables.tf
Droot/main.tf, root/dev.tf, root/prod.tf, root/variables.tf
Attempts:
2 left
💡 Hint

Think about how to keep environment files separate and complete with their own variables.

Configuration
intermediate
1:30remaining
Determine which Terraform file will load variables for the production environment

Given this file structure:

root/
  main.tf
  variables.tf
  prod/
    main.tf
    variables.tf
  dev/
    main.tf
    variables.tf

When running Terraform in the prod folder, which variables.tf file is loaded?

ABoth root/variables.tf and prod/variables.tf
Bprod/variables.tf
Cdev/variables.tf
Droot/variables.tf
Attempts:
2 left
💡 Hint

Terraform loads variables from the current working directory.

service_behavior
advanced
1:30remaining
What happens if Terraform files are duplicated in root and environment folders?

You have main.tf files in both the root folder and the dev folder. You run Terraform commands inside the dev folder. What will Terraform do?

ATerraform only uses the main.tf in the current <code>dev</code> folder
BTerraform merges both main.tf files automatically
CTerraform throws an error about duplicate main.tf files
DTerraform uses the root main.tf and ignores the dev folder
Attempts:
2 left
💡 Hint

Terraform works with files in the current directory only.

security
advanced
1:30remaining
Which file should NOT contain sensitive data in a Terraform project?

In a Terraform project with multiple files, which file is the least appropriate place to store sensitive information like passwords or API keys?

Amain.tf
Bterraform.tfvars
Cvariables.tf
Dsecret.auto.tfvars
Attempts:
2 left
💡 Hint

Think about which files are meant for configuration vs. variable values.

Best Practice
expert
2:30remaining
Choose the best Terraform file structure for reusable modules and environment configs

You want to create reusable Terraform modules and separate environment configurations. Which file structure below follows best practices?

A
root/
  main.tf
  variables.tf
  dev_main.tf
  prod_main.tf
B
root/
  network_module.tf
  compute_module.tf
  dev.tf
  prod.tf
C
root/
  modules/
    main.tf
  dev/
    main.tf
  prod/
    main.tf
D
root/
  modules/
    network/
      main.tf
    compute/
      main.tf
  envs/
    dev/
      main.tf
    prod/
      main.tf
Attempts:
2 left
💡 Hint

Think about separating reusable code and environment-specific configs clearly.