Terraform
State, modules, workflows, drift, remote state, and infrastructure design.
What is the Terraform state file and why is it important?
Terraform state tracks real infrastructure resources and maps them to your code.
Why should Terraform state be stored remotely?
Remote state improves collaboration, security, and locking.
What are Terraform modules?
Modules are reusable groups of Terraform resources.
What is the difference between terraform plan and terraform apply?
plan previews changes, while apply executes them.
What does tainting a resource mean in Terraform?
It marks a resource for forced recreation during the next apply.
What are Terraform workspaces?
Workspaces allow multiple state instances for the same Terraform configuration.
What is the lifecycle block in Terraform?
The lifecycle block controls how Terraform creates, updates, or destroys resources.
What is infrastructure drift?
Drift happens when real infrastructure differs from Terraform state or configuration.
What is terraform import?
It allows bringing existing infrastructure into Terraform state.
How does Terraform handle dependencies?
Terraform builds a dependency graph based on resource references.
What is Terraform?
Terraform is an Infrastructure as Code tool used to provision and manage infrastructure.
What is a provider in Terraform?
A provider is a plugin that lets Terraform interact with an external platform or service.
What is a resource in Terraform?
A resource is a block that defines an infrastructure object Terraform will manage.
What is a variable in Terraform?
A variable makes Terraform configurations reusable and configurable.
What is an output in Terraform?
An output exposes values from Terraform after apply.
What is main.tf?
main.tf is commonly used as the primary Terraform configuration file.
What is a .tfvars file?
A .tfvars file provides values for input variables.
Why is state locking important in Terraform?
State locking prevents multiple users from modifying the same state at the same time.
What is a backend in Terraform?
A backend defines where Terraform stores its state.
What is the difference between local state and remote state?
Local state is stored on the local machine, while remote state is stored in shared remote storage.
What is a module in Terraform?
A module is a reusable collection of Terraform resources.
What is the difference between a root module and a child module?
The root module is the main working directory, while child modules are called by it.
What does declarative mean in Terraform?
Declarative means you describe the desired end state, not each step to get there.
What does idempotent mean in Terraform?
It means repeated applies should result in the same infrastructure state if nothing changed.
What does Terraform refresh do conceptually?
It updates state to match the real infrastructure.
What does terraform init do?
terraform init initializes the working directory and downloads required providers and modules.
What does terraform validate do?
terraform validate checks whether the configuration is syntactically valid.
What does terraform fmt do?
terraform fmt formats Terraform files consistently.
What does terraform show do?
terraform show displays human-readable information about state or plan files.
What does terraform graph do?
terraform graph visualizes resource dependencies.
What is a typical Terraform workflow?
A typical workflow is init, validate, plan, and apply.
What is the difference between count and for_each in Terraform?
count uses numeric indexes, while for_each uses keys for more stable resource management.
What are locals in Terraform?
Locals are named expressions used to simplify and reuse values inside Terraform code.
What is a data source in Terraform?
A data source reads information from existing infrastructure without creating it.
When should depends_on be used in Terraform?
depends_on should be used when Terraform cannot infer a dependency automatically.
What does sensitive mean in Terraform outputs or variables?
Sensitive values are hidden from normal CLI output to reduce exposure.
Why would Terraform recreate a resource instead of updating it?
Some resource attributes cannot be updated in place and require replacement.
What does terraform apply -target do and why should it be used carefully?
It applies changes only to selected resources, but it can bypass the normal full dependency workflow.
What are Terraform best practices for production environments?
Use remote state, locking, modules, code review, validation, and separate environments safely.
Why do some teams use Terragrunt with Terraform?
Terragrunt helps manage repetition, environment structure, and remote state configuration around Terraform.