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?
Think about how to keep environment files separate and complete with their own variables.
Option C correctly places environment-specific files in separate folders with their own main and variables files, allowing isolated configurations per environment.
Given this file structure:
root/
main.tf
variables.tf
prod/
main.tf
variables.tf
dev/
main.tf
variables.tfWhen running Terraform in the prod folder, which variables.tf file is loaded?
Terraform loads variables from the current working directory.
Terraform loads variables.tf from the current directory where the command runs, so prod/variables.tf is used when running in the prod folder.
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?
Terraform works with files in the current directory only.
Terraform loads configuration files only from the current working directory. It does not merge files from parent directories.
In a Terraform project with multiple files, which file is the least appropriate place to store sensitive information like passwords or API keys?
Think about which files are meant for configuration vs. variable values.
main.tf defines resources and should not contain sensitive values directly. Sensitive data belongs in variable files or separate secure files.
You want to create reusable Terraform modules and separate environment configurations. Which file structure below follows best practices?
Think about separating reusable code and environment-specific configs clearly.
Option D cleanly separates reusable modules under modules/ and environment configs under envs/, which is a recommended best practice.