Learn Terraform core architecture, production scenario-based questions, incident response, and real-world engineering solutions.
❓ Q1: What is Infrastructure as Code (IaC), and what actual problems does it solve for an operations team?
Click on the dropdown below to reveal the technical answer.
Answer: Infrastructure as Code (IaC) is the practice of provisioning, managing, and configuring IT infrastructure (servers, network topologies, storage, load balancers) using machine-readable configuration files or scripts ("code"), rather than relying on manual server configuration, physical hardware setups, or interactive GUI dashboard configurations.
❓ Q2: How do you choose between a provisioning tool like Terraform and a configuration management tool like Ansible?
Click on the dropdown below to reveal the technical answer.
Answer:
❓ Q3: Walk me through the standard Terraform core workflow. What happens under the hood during each phase?
Click on the dropdown below to reveal the technical answer.
Answer: The standard Terraform core workflow consists of three primary phases:
terraform init & Coding): Author HCL configuration files defining the desired infrastructure. Run terraform init to download the required provider plugins (e.g., AWS, Azure) and initialize the backend.terraform plan): Compare the configuration against the real-world infrastructure and state file. Generate an execution plan showing what actions (create, update, destroy) will be performed.terraform apply): Execute the actions proposed in the plan. Terraform calls the provider APIs to provision the resources and updates the local or remote state file (terraform.tfstate).❓ Q4: What is the difference between count and for_each? In what scenarios is for_each the safer choice?
Click on the dropdown below to reveal the technical answer.
Answer:
count:
count = 3).aws_subnet.subnets[0]).count only for identical, simple resources.for_each:
aws_subnet.subnets["public-1"]).for_each for complex configurations and variable maps.❓ Q5: How do dynamic blocks work in Terraform, and can you give me an example of when they are necessary?
Click on the dropdown below to reveal the technical answer.
Answer: Dynamic Blocks allow you to generate repeated nested blocks within a resource or data source dynamically based on a variable list or map (e.g., dynamically creating multiple ingress ports in a security group):
resource "aws_security_group" "sg" {
name = "dynamic-ports"
dynamic "ingress" {
for_each = var.ports
content {
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
}
❓ Q6: How do you distinguish between input variables and local values? When should we use locals?
Click on the dropdown below to reveal the technical answer.
Answer:
variable): Act as function arguments. They allow users to pass custom input parameters into your modules to customize execution (e.g., changing AMI IDs or environment tags).locals): Act as local variables within a program. They are internal to the configuration, cannot be overridden externally, and are used to store intermediate calculations or avoid hardcoding repeated expressions.❓ Q7: Can you explain the difference between a resource block and a data source block?
Click on the dropdown below to reveal the technical answer.
Answer:
resource): Infrastructure components that Terraform creates, manages, updates, and destroys (e.g., creating a new EC2 instance).data): Read-only queries used to fetch information from external APIs or pre-existing cloud resources (e.g., retrieving the latest AMI ID or querying an existing VPC ID).❓ Q8: What is the purpose of the Terraform state file, and what strategies do you implement to secure it in production?
Click on the dropdown below to reveal the technical answer.
Answer:
The state file (terraform.tfstate) is Terraform's database mapping your HCL configurations to actual physical resources deployed in the cloud. It tracks metadata, dependencies, and resources.
terraform.tfstate to Git. Store it in a remote backend like Amazon S3 or Google Cloud Storage.❓ Q9: If our remote state file gets corrupted or accidentally deleted, how would you recover it?
Click on the dropdown below to reveal the technical answer.
Answer:
terraform import commands.terraform.tfstate.backup files.❓ Q10: If our Terraform codebase grows into a monolithic state file, how would you split it into modular configurations?
Click on the dropdown below to reveal the technical answer.
Answer: A monolithic state file increases deployment risk and planning times. To split it:
networking, database, app).terraform state mv to move resources from the old monolithic state to the new layer-specific state files.terraform_remote_state) in the application layer to fetch outputs (e.g., VPC IDs) from the networking state.❓ Q11: How do you safely migrate a Terraform state file from a local backend to a remote backend?
Click on the dropdown below to reveal the technical answer.
Answer:
backend block in your HCL code to point to the new backend configuration (e.g., switching from local to S3).terraform init.yes to upload the state database to the new remote storage automatically.❓ Q12: How do tools like Terragrunt, Terraform Cloud, and Atlantis help scale Terraform in an enterprise?
Click on the dropdown below to reveal the technical answer.
Answer:
terraform plan and comments the output on the PR; once reviewed, the developer merges the PR by commenting atlantis apply.❓ Q13: What is your approach to implementing a GitOps model for infrastructure delivery using Terraform?
Click on the dropdown below to reveal the technical answer.
Answer:
main, the controller automatically runs terraform apply in a secure runner, keeping the cloud environment synced with Git without manual shell intervention.❓ Q14: How does Terraform compare to AWS CloudFormation, and why might you prefer one over the other?
Click on the dropdown below to reveal the technical answer.
Answer: