0
0
Terraformcloud~20 mins

Terraform file organization - Practice Problems & Coding Challenges

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

You have a Terraform project that manages infrastructure for two environments: production and staging. Which file organization below best separates environment-specific configurations while reusing common modules?

ASeparate folders for each environment (prod/, staging/) each containing main.tf, variables.tf, and backend.tf files, plus a modules/ folder for reusable modules.
BA single main.tf file with all resources and variables for both environments mixed together.
COne folder with main.tf and variables.tf files, and environment variables set externally to switch environments.
DMultiple .tf files in the root folder named prod.tf, staging.tf, and modules.tf without folders.
Attempts:
2 left
💡 Hint

Think about how to isolate environment settings while sharing common code.

Best Practice
intermediate
2:00remaining
Choose the best practice for Terraform state file management

Which Terraform file organization practice helps prevent state file conflicts when multiple team members work on the same infrastructure?

AStore the state file locally on each developer's machine.
BUse a remote backend like S3 or Terraform Cloud with locking enabled, and organize state files per environment.
CKeep all environment states in a single shared state file in the root folder.
DCommit the state file to the version control system along with .tf files.
Attempts:
2 left
💡 Hint

Think about collaboration and avoiding overwriting each other's work.

service_behavior
advanced
2:00remaining
What happens if you mix provider configurations in multiple Terraform files without explicit aliasing?

Consider a Terraform project with two .tf files: one configures AWS provider with region us-east-1, and another configures AWS provider with region us-west-2, both without aliases. What is the expected behavior when running terraform apply?

ATerraform will merge both provider configurations and apply resources in both regions automatically.
BTerraform will use the last declared provider configuration and ignore the first one.
CTerraform will throw a configuration error due to multiple provider blocks without aliases.
DTerraform will create duplicate resources in both regions without error.
Attempts:
2 left
💡 Hint

Think about how Terraform handles multiple provider blocks of the same type.

security
advanced
2:00remaining
Identify the security risk in Terraform file organization

Which Terraform file organization practice can lead to accidental exposure of sensitive data like secrets or passwords?

AUsing <code>terraform.tfvars</code> files committed to version control containing secrets in plain text.
BStoring sensitive variables in a separate <code>variables.tf</code> file with no special handling.
CReferencing sensitive data from environment variables during Terraform runs.
DUsing remote state backends with encryption enabled.
Attempts:
2 left
💡 Hint

Consider what happens if secret values are stored in files tracked by Git.

🧠 Conceptual
expert
2:00remaining
Determine the number of Terraform state files in a recommended multi-module, multi-environment setup

You have a Terraform project organized with a modules/ folder containing reusable modules, and separate folders for dev/, qa/, and prod/ environments. Each environment folder has its own Terraform configuration files and remote backend configured. How many distinct Terraform state files will exist after applying all environments?

AOne state file per module per environment.
BOne state file per module, shared across all environments.
COne single state file for all environments and modules combined.
DOne state file per environment, encompassing all modules used in that environment.
Attempts:
2 left
💡 Hint

Think about how Terraform state files track resources per configuration and environment.