In Terraform, you can split your infrastructure code into multiple .tf files. What is the main reason for doing this?
Think about how organizing files helps when your project grows.
Using multiple .tf files helps keep your code organized by grouping related resources or configurations. Terraform automatically loads all .tf files in a directory, so splitting files is for clarity and maintainability, not a requirement or performance boost.
You want to define input variables for your Terraform project. Which file name follows common naming conventions?
Look for the standard file name used in most Terraform projects.
The file variables.tf is the common convention to define input variables. Files ending with .tfvars are used to provide values, not definitions. Using .txt or long descriptive names is not standard.
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?
Think about how Terraform identifies resources uniquely.
Terraform requires resource names to be unique within a module. Defining two resources with the same type and name causes a conflict error during plan or apply.
You manage multiple environments like dev and prod in the same Terraform project. Which file naming approach is best to keep environment configs separate?
Think about how Terraform loads variable values from files.
Using separate .tfvars files for each environment is a common practice. You keep the main configuration files the same and pass different variable values per environment by specifying the appropriate .tfvars file during commands.
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?
Think about how Terraform uses the state file to track resources.
The terraform.tfstate file is where Terraform stores the current state of managed infrastructure. If you create this file manually with invalid content, Terraform will try to read it and may fail or behave unexpectedly.