Terraform IaC Concepts Interview Questions (2027)

30 Terraform infrastructure as code interview questions on concepts: declarative IaC, idempotence, state, drift, modules, blast radius and tool trade-offs.

Sep 12, 2025 - 11:40
Nov 12, 2026 - 13:05
 0  46
Terraform IaC Concepts Interview Questions (2027)

Terraform infrastructure as code interview questions test the ideas behind the tool: why infrastructure belongs in version control, declarative versus imperative configuration, idempotence, state, drift, immutable infrastructure, module design, blast radius, policy as code and how Terraform compares with CloudFormation, Pulumi and Ansible. This page answers 30 concept questions for the theory and design round.

It complements our command-focused Terraform quick-answer FAQs. Where answers mention Terraform behaviour, they were checked against HashiCorp's documentation in November 2026, with Terraform v1.17.2 as the latest stable release. The broadest Terraform question bank on this blog is our 120+ Terraform interview questions, and the IaC topic pillar is the 12 infrastructure as code tools ranked for DevOps.

Key takeaways

  • Infrastructure as code means environments are created from reviewed, versioned files rather than console clicks, so changes are repeatable and auditable.
  • Terraform is declarative: you describe the end state, and Terraform works out the create, update and delete steps from the difference between code, state and reality.
  • State is what lets Terraform map code to real objects. Protect it, lock it and split it so one mistake cannot affect everything.
  • Drift happens whenever someone changes infrastructure outside the code. Detect it with regular plans and fix the process that allowed it.
  • Good module design is about clear inputs and outputs and small blast radius, not about putting everything in one reusable block.
  • Interviewers reward trade-offs. Saying when you would not use Terraform is often a stronger answer than praising it.

IaC tools compared

Expect at least one comparison question. Keep answers about model and fit, not about which tool is "best".

ToolStyleLanguageStateTypical fit
Terraform / OpenTofuDeclarative provisioningHCLState file in a backendMulti-cloud and SaaS resources from one workflow
AWS CloudFormationDeclarative provisioningJSON or YAMLManaged by AWS in stacksAWS-only estates that want a native service
AWS CDKCode that generates CloudFormationTypeScript, Python, Java and othersCloudFormation stacksTeams who prefer general-purpose languages on AWS
PulumiDeclarative engine driven by codeGeneral-purpose languagesPulumi state backendDevelopers who want loops, classes and tests in a familiar language
AnsibleProcedural tasks with idempotent modulesYAMLNo state fileConfiguring operating systems and applications on existing servers

IaC fundamentals

1. What is infrastructure as code?

It is the practice of defining servers, networks, databases, permissions and other infrastructure in files that tools apply automatically. The files live in version control, changes go through review, and the same code can build identical environments. It replaces manual console changes that nobody can reproduce or audit.

2. What problems does IaC solve?

It removes configuration that exists only in someone's memory, makes environments consistent, speeds up building new ones, gives an audit trail through Git history and lets you rebuild after a disaster from code. It also makes infrastructure changes reviewable in the same way application changes are.

3. What is the difference between declarative and imperative IaC?

Declarative code states the desired end result, such as "three subnets exist with these ranges", and the tool works out the steps. Imperative code lists the steps, such as "create subnet A, then B". Terraform is declarative, which is why rerunning it does nothing when reality already matches. We cover this in more depth in declarative versus imperative configuration in IaC.

4. What does idempotent mean for IaC?

Applying the same code repeatedly produces the same result. The first apply creates resources, and later applies change nothing unless the code or reality changed. Idempotence is what makes it safe to run IaC from a pipeline on every merge.

5. What is the difference between provisioning and configuration management?

Provisioning creates the infrastructure itself: networks, instances, managed databases, load balancers. Configuration management sets up what runs inside servers: packages, files and services. Terraform is mainly a provisioning tool, while Ansible, Puppet and Chef are configuration management tools. Many teams use both, or replace in-server configuration with prebuilt images and containers.

6. What is immutable infrastructure?

Instead of changing a running server, you build a new image or container with the change and replace the old one. Servers are never patched in place. This reduces drift and makes rollbacks simpler, because you redeploy the previous image. Terraform supports this pattern through launch templates, instance replacement and create_before_destroy.

State and drift

7. Why does Terraform need state when CloudFormation does not expose a state file?

Terraform must remember which real object each block manages, because providers cannot always find resources by name. CloudFormation also tracks this, but AWS stores it inside the stack service. Terraform keeps it in a state file you control, which is what allows it to manage many providers from one tool.

8. What are the risks of state?

State can contain secrets in plain text, so leaked state is a security incident. Lost or corrupted state means Terraform no longer knows what it manages. Two applies writing at once can corrupt it. The answers are an encrypted remote backend, locking, versioning and tight access control.

9. How should state be split?

Split by lifecycle and ownership, for example networking, shared platform services and each application, with separate states per environment. Smaller states mean faster plans, fewer people needing access, and a smaller blast radius when something goes wrong. Avoid splitting so finely that every change needs coordinated applies across ten stacks.

10. What is configuration drift?

Drift is any difference between real infrastructure and what the code and state describe, usually from manual console changes, other automation, or emergency fixes that were never written back to code. Drift makes the next apply unpredictable because Terraform will try to undo the change. Our article on why infrastructure drift is a silent problem covers detection and prevention.

11. How do you handle drift you want to keep?

Update the code to match the change, then run terraform plan -refresh-only and apply it so state records reality. If the change should not stay, run a normal plan and apply to revert it. Either way, find out how it happened and remove that path, usually by restricting console write access.

12. Is drift ever acceptable?

Some attributes are expected to change outside Terraform, such as the desired count of an autoscaling group managed by a scaler. Mark those with ignore_changes so plans stay clean. Anything else should be treated as drift to fix, otherwise plans become noise and real problems get missed.

Design and modules

13. What makes a good Terraform module?

A clear purpose, a small and documented set of input variables with types and validation, useful outputs, sensible defaults and no hidden provider configuration. It should do one job, such as a VPC or a service deployment, and be versioned so callers upgrade on purpose. Our guide on where reusable Terraform modules help gives examples.

14. What is blast radius, and how does IaC design reduce it?

Blast radius is how much can break from one mistaken change. You reduce it by splitting state, separating environments into different accounts or subscriptions, giving pipelines only the permissions they need, and protecting critical data resources with prevent_destroy. A typo in an app stack should never be able to delete the shared network.

15. How do you structure code for dev, staging and production?

Common patterns are one root module per environment calling shared modules with different variables, or one configuration with separate variable files and backends. Many teams prefer separate directories for production because differences become visible in review and permissions can differ. CLI workspaces suit short-lived copies better than long-lived production environments.

16. Should you wrap every public module in your own module?

Not by default. A thin wrapper that only passes variables through adds maintenance without value. Wrap when you need to enforce company standards, such as required tags, encryption or naming, so every team gets those settings without remembering them.

17. How do you version infrastructure code?

Keep it in Git, tag module releases with semantic versions, pin module and provider versions in callers and commit the provider lock file. Apply only from the main branch through a pipeline, so Git history matches what is deployed. Our post on how Terraform fits the DevOps workflow walks through plan-to-apply in a pipeline.

Security and governance

18. How do you keep secrets out of IaC?

Never write secrets in .tf files or tfvars committed to Git. Read them at run time from a secrets manager, generate them inside the provider where possible, and protect state because values may still end up there. sensitive = true only hides values from output. Newer Terraform versions add ephemeral values and write-only arguments that keep supported values out of state.

19. What is policy as code?

Rules about infrastructure written as code and checked automatically, such as "storage must be encrypted" or "no security group open to 0.0.0.0/0 on port 22". Tools like Open Policy Agent, HashiCorp Sentinel or static scanners evaluate plans or code in CI and block changes that break the rules. It replaces manual review checklists.

20. How do you stop misconfigurations from reaching production?

Run static scanners and policy checks on every pull request, require plan review, apply through a pipeline with least-privilege credentials, and enable cloud-side guardrails as a last line. Our article on how DevSecOps prevents IaC misconfigurations covers the tool options.

21. How should pipelines authenticate to the cloud?

Use short-lived credentials through OIDC federation from the CI system to the cloud provider, with roles scoped to each stack. Avoid long-lived access keys stored as pipeline variables, since they leak and are rarely rotated.

Testing and delivery

22. How do you test infrastructure code?

Use layers. Formatting, validation and linting catch syntax and style problems. Static security and policy checks catch risky settings. terraform test files, available since v1.6.0, check module logic with plan-only runs or real applies in a sandbox. Finally, a short smoke test after deployment confirms the service actually works.

23. Why review the plan rather than the code alone?

The code shows intent, but the plan shows what will actually happen to real resources, including replacements caused by an attribute that forces recreation. Reviewers should look for unexpected destroys and replacements before approving.

24. What is GitOps, and how does it relate to IaC?

GitOps treats Git as the source of truth and uses automation to make the running system match it, often with an agent that continuously reconciles. Applying Terraform only from merged commits through a pipeline follows the same idea. Kubernetes tools such as Argo CD apply it continuously to cluster objects.

Comparison and trade-off questions

25. Terraform or CloudFormation for an AWS-only company?

CloudFormation is native, needs no state backend and gets AWS support. Terraform covers other providers too, such as DNS, monitoring and Git hosting, from one workflow and has a large module ecosystem. If the company also manages non-AWS services, Terraform's single workflow is a strong argument. If it is strictly AWS and values native tooling, CloudFormation or CDK is reasonable.

26. When would you choose Pulumi over Terraform?

When the team is mostly developers who want to use a general-purpose language with loops, functions, packages and unit-test frameworks they already know. The trade-off is that code can become harder for operations staff to review than HCL.

27. When would you not use Terraform?

For configuring software inside long-lived servers, where Ansible or images fit better. For Kubernetes application deployments that change many times a day, where GitOps tools are usually a better fit. And for one-off experiments that will be thrown away within an hour.

28. What is OpenTofu?

OpenTofu is an open source fork of Terraform maintained under the Linux Foundation. It uses HCL and a similar workflow, and its latest release in November 2026 was v1.13.9. Features have started to diverge, so check compatibility before switching an existing codebase.

Scenario questions

29. Your company has 300 manually built resources. How do you move to IaC?

Start with an inventory and pick one low-risk area, such as DNS or a non-production network. Write code for it, bring the resources in with import blocks, and confirm plan shows no changes before going further. Then restrict console write access for that area. Repeat in order of risk and value rather than trying to import everything at once.

30. A plan to change a tag wants to replace a production database. What do you do?

Stop and read why the plan shows replacement; usually a different attribute changed or a provider upgrade changed behaviour. Fix the cause, add prevent_destroy to the database so future plans fail instead, and make replacement of stateful resources a required reviewer check in the pipeline.

How to prepare

Practise explaining each concept with an example from your own lab: a drift you created and fixed, a module you designed, a state split you would choose. Concept rounds go well when every answer ties back to something concrete. Pair this page with the command sheet linked at the top. For hands-on practice with an instructor, our Terraform training in Pune runs in the Kharadi classroom and live online.

Frequently asked questions

Is Terraform declarative or imperative?

Declarative. You describe the end state, and Terraform plans the steps from the difference between code, state and real infrastructure.

What is the difference between Terraform and Ansible?

Terraform mainly provisions infrastructure and tracks it in state. Ansible mainly configures existing servers with idempotent tasks and keeps no state file.

Why is Terraform state sensitive?

It can contain secrets in plain text and is the map of everything Terraform manages, so it needs encryption, locking and restricted access.

What is configuration drift?

Any difference between real infrastructure and what the code and state describe, usually caused by manual changes outside Terraform.

What is policy as code?

Infrastructure rules written as code and checked automatically in CI, using tools such as Open Policy Agent, Sentinel or static scanners.

What is immutable infrastructure?

Replacing servers or containers with new versions instead of changing them in place, which reduces drift and simplifies rollback.

Is OpenTofu the same as Terraform?

No. It is an open source fork under the Linux Foundation with its own releases. It is similar but not identical, so check feature compatibility.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.