0
0
Terraformcloud~20 mins

File naming conventions (.tf files) in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform File Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use multiple .tf files in a Terraform project?

In Terraform, you can split your infrastructure code into multiple .tf files. What is the main reason for doing this?

ABecause Terraform requires each resource to be in a separate file to work correctly.
BTo organize code logically by resource type or purpose, making it easier to manage and understand.
CTo speed up Terraform plan and apply commands by parallel processing files.
DTo avoid using variables and outputs in the configuration.
Attempts:
2 left
💡 Hint

Think about how organizing files helps when your project grows.

Best Practice
intermediate
2:00remaining
Which file name is best for defining variables in Terraform?

You want to define input variables for your Terraform project. Which file name follows common naming conventions?

Aterraform_variables.tf
Binput.tfvars
Cvars.txt
Dvariables.tf
Attempts:
2 left
💡 Hint

Look for the standard file name used in most Terraform projects.

Configuration
advanced
2:00remaining
What happens if you have two files defining the same resource name?

Consider these two files in the same Terraform directory:

file1.tf:
resource "aws_s3_bucket" "mybucket" {
  bucket = "bucket-one"
}

file2.tf:
resource "aws_s3_bucket" "mybucket" {
  bucket = "bucket-two"
}

What will Terraform do when you run terraform plan?

ATerraform will raise an error about duplicate resource names and stop.
BTerraform will ignore the second resource and use only the first.
CTerraform will merge both resources into one with combined settings.
DTerraform will create two separate buckets with the same name.
Attempts:
2 left
💡 Hint

Think about how Terraform identifies resources uniquely.

Architecture
advanced
2:00remaining
How should you name files to separate environment configurations?

You manage multiple environments like dev and prod in the same Terraform project. Which file naming approach is best to keep environment configs separate?

AUse files named <code>dev.tfvars</code> and <code>prod.tfvars</code> to hold environment-specific values.
BPut all environment configs in one file named <code>environment.tf</code> with comments.
CCreate separate directories named <code>dev</code> and <code>prod</code> with identical file names inside.
DUse a single file named <code>main.tf</code> and switch values manually before each run.
Attempts:
2 left
💡 Hint

Think about how Terraform loads variable values from files.

service_behavior
expert
2:00remaining
What is the effect of naming a file terraform.tfstate in your working directory?

You accidentally create a file named terraform.tfstate manually in your Terraform directory before running any commands. What will happen when you run terraform apply?

ATerraform will overwrite the file without warning and proceed normally.
BTerraform will ignore the file and create its own state file elsewhere.
CTerraform will treat the file as the state file and may cause conflicts or errors if its content is invalid.
DTerraform will rename the file automatically to avoid conflicts.
Attempts:
2 left
💡 Hint

Think about how Terraform uses the state file to track resources.