INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 91–105 of 190 questions
91.What is a good way to test that a module's variable validation works?SeniorTerraform
Write a terraform test file with a run block that uses command = plan and expect_failures = [var.NAME]. The test passes when the validation rejects the bad value.
92.What does a Terraform provider need to implement for each resource?SeniorTerraform
A schema that describes its fields, plus Create, Read, Update and Delete functions that call the service API. Read also removes the resource from state if the API says it no longer exists.
93.The state lock is stuck. What do you do?SeniorTerraform
Read the error to see the lock ID and who holds it, then check that no pipeline is still running for that stack. Only when you are sure the job died, run terraform force-unlock LOCK_ID, then terraform plan to confirm state is healthy. Prevent it with CI-only applies and job timeouts that let Terraform exit cleanly.
94.An apply failed halfway. What state are you in?SeniorTerraform
Terraform saves state after each resource, so what succeeded is recorded and what failed is not. Fix the cause (permissions, quota, a bad value, an API timeout) and run plan again: it shows only the remaining work. Resources created but left broken are marked tainted and replaced on the next apply.
95.A plan says your production database will be replaced. What do you do?SeniorTerraform
Stop and don't apply. Find the attribute marked # forces replacement. A rename needs a moved block; a value changed outside Terraform needs the code aligned or ignore_changes; a change that truly needs replacement needs a planned migration (snapshot, new instance, cutover). Add prevent_destroy and the database's own deletion protection so this fails loudly next time.
96.The state file is lost or corrupted. How do you recover?SeniorTerraform
Stop all applies for that stack first. Restore the last good version from backend versioning and run plan, which should show few or no changes. With no backup, rebuild state by writing import blocks for each resource (plan -generate-config-out helps) until the plan is clean.
97.Terraform or Ansible: what is the difference?SeniorTerraform
Terraform provisions infrastructure declaratively and tracks it in state: networks, clusters, databases, IAM. Ansible configures what runs inside machines: packages, files and services. They work together, for example Terraform builds the instance and Ansible or cloud-init sets it up.
98.Your single state has grown huge and slow. What do you do?SeniorTerraform
Split it into smaller stacks by how often things change and who owns them, such as network, data and apps. Move resources with moved blocks or state commands, share values through outputs and terraform_remote_state or a parameter store, and use Terragrunt or pipelines to run stacks in order.
99.Why use OpenTofu or HCP Terraform?SeniorTerraform
OpenTofu is an open-source fork with a community license and extras such as state encryption, and it uses the same HCL for most code. HCP Terraform is a managed service that runs plans and applies, stores and locks state, keeps history and runs policy. The choice depends on license, cost and how much you want to run yourself.
100.What are the signs that a Terraform state is too big?SeniorTerraform
Plans take many minutes, people wait for state locks, one mistake can touch unrelated systems, and teams need different access to different parts. These are the signs to split it into smaller stacks.
101.Someone applied from their laptop and broke prod. How do you stop it happening again?SeniorTerraform
Make CI the only path: the production write role can only be assumed by the pipeline through OIDC, the state bucket is locked down, and every change needs a reviewed merge request with a plan. Add drift detection so manual changes are spotted quickly.
102.How do you handle a Lambda that fails on some messages?SeniorAWS
Set a dead-letter queue or an on-failure destination, make the code safe to run twice, use partial batch responses with SQS, and set retries and timeouts so failures do not repeat forever.
103.Why use CloudFormation or CDK instead of the console?SeniorAWS
Templates are repeatable, reviewed and versioned. Stacks know what they own, so updates and deletes are clean, and drift detection shows manual changes. CDK lets you write the templates in a normal programming language.
104.How do you keep secrets out of code on AWS?SeniorAWS
Store them in Secrets Manager or Parameter Store, encrypted with KMS, and give the app role permission to read only its own secrets. Rotate them, and never place them in templates or images.
105.What are SCPs?SeniorAWS
Service control policies in AWS Organizations set the maximum permissions for accounts. They never grant access, they only limit it, so even an admin in a member account cannot do what the SCP denies.