DevOps Interview Questions: Declarative vs Imperative IaC
Reviewed by Mark Dickie · Last updated
14 questions on this page you can answer and see marked on the spot. Go to the first one
Declarative and imperative are two paradigms for managing infrastructure as code (IaC), and the difference between them is one of the most common interview topics in a DevOps round. In a declarative approach you describe the desired end state of your infrastructure and let the tool figure out how to get there. In an imperative approach you give explicit, step-by-step instructions that tell the tool what to do and in what order. Terraform and CloudFormation are declarative; Ansible and Bash scripts are imperative. Interviewers want to see that you can name tools on each side, explain when one fits better than the other, and reason about idempotency, state drift, and reconciliation.
What is the difference between declarative and imperative IaC?
| Aspect | Declarative | Imperative |
|---|---|---|
| You describe | The desired end state | The sequence of actions |
| Tool decides | How to reach that state | Nothing — you script every step |
| Idempotency | Built in (re-running converges to state) | You must code it yourself |
| Drift detection | Supported via state files | Not automatic |
| Examples | Terraform, CloudFormation, Pulumi (with desired-state APIs) | Ansible (task mode), Bash, Cloud-init scripts |
What should I know for a declarative-vs-imperative interview question?
- Be able to define both paradigms in one sentence each and give a concrete tool example for each.
- Explain idempotency: why re-running a declarative config produces the same result, and why that matters for pipelines.
- Know how state files work in Terraform — they store the last-known infrastructure state so the tool can diff and reconcile.
- Discuss when imperative still wins: ad-hoc tasks, configuration that changes per run, or environments where a step-by-step order is required (e.g. a rolling restart sequence).
- Be ready to explain drift: what happens when someone changes infrastructure outside of IaC, and how a declarative tool can detect or correct it.
Can a tool be both declarative and imperative?
Yes. Ansible lets you write imperative playbooks with command and shell tasks, but its core modules like apt, file, and service are declarative — you specify the desired package state and Ansible handles the steps. Pulumi supports an imperative programming model in TypeScript, Python, and Go, yet the infrastructure it provisions is described as a desired state. The interview point is that the paradigms describe how you express intent, not a hard partition between tools.
Key facts
- Tarmac's DevOps interview questions cover 24 questions at difficulty 1–5 of 5.
- Tarmac tracked 2,457 job postings asking for DevOps in November 2026.
- Roles asking for DevOps advertise a median base salary of £75,000, across 755 job postings as of November 2026.
- Tarmac last reviewed these DevOps interview questions on 13 October 2026.
At a glance
| Questions | 24 |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | True / false, Multiple choice, Ordering, Fill in the blank, Short answer, Design exercise, Multiple answer |
What you'll review
- declarative vs imperative
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
A declarative Infrastructure-as-Code tool like Terraform specifies the desired end state of infrastructure (e.g., "ensure 3 web servers exist") rather than the step-by-step commands needed to reach that state.#
Options
Show answer
True. Declarative Infrastructure-as-Code tools like Terraform express the desired end state of infrastructure — for example, "ensure 3 web servers exist" — and the tool itself computes and applies the steps to reach that state. Imperative approaches, such as shell scripts issuing explicit API calls, spell out each step individually.
Declarative IaC describes the desired end state — what the infrastructure should look like — and leaves it to the tool to figure out how to get there. Imperative IaC, by contrast, lists the explicit sequence of actions (create this, then configure that). Terraform, CloudFormation, and Pulumi's declarative DSLs are declarative; a shell script that runs aws ec2 run-instances three times is imperative.
Which statement correctly describes the declarative approach to infrastructure-as-code?#
Options
Show answer
The declarative approach to infrastructure-as-code describes the desired end state of the infrastructure, and the tool works out the steps needed to reach that state and correct any drift. Imperative IaC, by contrast, specifies the exact commands to run in sequence.
Declarative IaC states the desired final state of the infrastructure (for example, three web servers behind a load balancer) and leaves the sequence of actions to the tool, which also reconciles drift when the real state diverges. The option describing exact ordered commands is the imperative approach, and the option requiring the operator to specify creation order step by step is also imperative in nature. The option claiming declarative IaC cannot be expressed as code files is false, since declarative IaC is written as code files such as manifests or templates.
True or false: In a declarative IaC tool such as Terraform, you must specify the exact sequence of commands needed to bring the infrastructure to its desired state.#
Options
Show answer
False. A declarative IaC tool such as Terraform requires you to describe the desired end state of the infrastructure, not the exact sequence of commands. The tool works out the necessary actions and their order itself; specifying the exact sequence of actions is the imperative approach.
This is false because a declarative IaC tool like Terraform only requires you to declare the desired end state, for example three web servers behind a load balancer. The tool itself computes the necessary actions, their order, and any reconciliation of drift. Specifying the exact sequence of commands is a hallmark of the imperative approach, not the declarative one.
True or false: in a declarative infrastructure-as-code tool such as Terraform, you describe the desired end state of the infrastructure (for example, '3 EC2 instances behind a load balancer') rather than the individual steps or commands needed to reach that state.#
Options
Show answer
True. In declarative infrastructure-as-code tools such as Terraform, you describe the desired end state, for example three EC2 instances behind a load balancer, and the tool works out the actions needed to reach it. Imperative approaches, such as shell scripts calling the AWS CLI, instead require you to spell out each step in order.
Declarative infrastructure-as-code tools let you specify the desired outcome, and the tool works out the sequence of actions needed to reach that state. Imperative IaC, such as shell scripts calling the AWS CLI, requires you to write out each step explicitly: create the security group, launch the instances, register them with the load balancer, and so on. Terraform is a canonical example of the declarative approach, so the statement is true.
In infrastructure-as-code, what distinguishes a declarative tool (e.g., Terraform, CloudFormation) from an imperative tool (e.g., a Bash script calling cloud APIs)?#
Options
Show answer
A declarative IaC tool lets you describe the desired end state of infrastructure and computes the steps to get there, whereas an imperative tool requires you to write the explicit sequence of actions yourself. Terraform and CloudFormation are declarative; a Bash script calling cloud APIs is imperative. The core difference is 'what' versus 'how.'
Declarative IaC tools like Terraform and CloudFormation let you describe the desired end state of your infrastructure; the tool's provider/executor computes the diff and applies the necessary changes to converge reality to that state. Imperative tools require you to spell out each step (e.g., create this, then update that). The option that says "A declarative tool requires you to write the exact sequence of API calls to reach the desired state, while an imperative tool lets you specify only the end state" reverses the definitions. The option that says "A declarative tool can only provision resources once and cannot detect drift on subsequent runs, whereas an imperative tool continuously reconciles state" is incorrect because declarative tools typically DO support drift detection on re-apply. The option that says "A declarative tool is always idempotent, while an imperative tool can never be made idempotent" overstates the claim — imperative scripts can be written to be idempotent, and declarative tools are not 'always' idempotent in every edge case, but the key distinction is the level of abstraction, not a guarantee of idempotency.
True or false: in declarative infrastructure-as-code, reapplying an unchanged configuration produces the same result, making the operation naturally idempotent, because the tool compares the current state to the desired state and makes no changes where they already match.#
Options
Show answer
Declarative infrastructure-as-code is idempotent. It describes the desired state, so the tool compares current state to it and applies only the differences. Reapplying an unchanged configuration is therefore a no-op that produces the same result. Imperative scripts often re-run every step unless explicitly guarded.
Declarative IaC describes the desired state rather than the sequence of operations. Because the tool compares the current state to the desired state and only applies changes where they differ, reapplying an unchanged configuration is a no-op, which is the hallmark of idempotency. The statement is therefore true. Imperative scripts, by contrast, may re-execute every step regardless of current state unless explicitly guarded.
Which statement correctly describes the fundamental difference between declarative and imperative Infrastructure as Code (IaC)?#
Options
Show answer
Declarative IaC describes the desired end state and lets the tool work out and apply the steps to reach it. Imperative IaC gives explicit, step-by-step commands to reach that state. Tools like Terraform and CloudFormation reconcile the actual infrastructure with the declared state on each run.
Declarative IaC (Terraform, CloudFormation, ARM, Pulumi in declarative mode) defines the desired end state, such as three VMs with these tags, and the tool computes and applies the steps to reach it, reconciling on each run. Imperative IaC (shell scripts, aws cli sequences, manual docker run chains) gives explicit step-by-step instructions to reach the state. The option that swaps the two definitions is wrong, the option claiming a location restriction for each style is false because both work on-premises and in cloud, and the option claiming declarative is always faster per run is false because per-run speed is not inherently better for either approach.
True or False: When an unchanged declarative IaC configuration is re-applied to infrastructure the tool already manages, the tool compares the desired state with its recorded or observed state, finds no difference, and makes no changes, so the run is idempotent.#
Options
Show answer
Re-applying an unchanged declarative configuration is idempotent: the tool compares desired state with its recorded or observed state, finds nothing to change, and makes no modifications. Imperative scripts lack this built-in comparison, so re-running them can create duplicates unless the commands are explicitly guarded.
Declarative IaC tools such as Terraform, CloudFormation, and Kubernetes manifests store or observe the current state and compare it with the desired configuration on each run. If the two already match, the tool plans no changes and the end state stays the same, which is the definition of idempotency. Imperative scripts do not perform this comparison by default, so re-running them can create duplicate resources or fail unless the commands are explicitly guarded.
A declarative IaC tool such as Terraform converges infrastructure to a desired configuration. Put these three steps in the order the tool performs them.#
Put these in order
Show answer
The order is: load the desired state from configuration files, compare it with actual infrastructure to compute a plan, then apply the computed changes. Declarative tools such as Terraform cannot compute a diff until the desired state is known, and cannot apply changes until the diff exists.
A declarative tool must first load the desired state from the authored configuration, since there is nothing to compare until that state exists. It then compares desired state against the actual infrastructure (Terraform's plan step includes refreshing actual state) to compute the diff. Only after the diff is computed can it apply the changes that move the real infrastructure toward the desired state. Each step depends on the output of the one before it, so the order is strict.
In a _____ approach to infrastructure as code, you describe the desired end state and let the tool compute the steps to reach it; in an _____ approach, you write the explicit sequence of commands that change the system step by step.#
Show answer
In a declarative approach to infrastructure as code, you describe the desired end state and let the tool compute the steps to reach it; in an imperative approach, you write the explicit sequence of commands that change the system step by step.
This is the foundational IaC distinction. A declarative approach states what you want — 'three web servers behind a load balancer with this config' — and the tool diffs that desired state against reality and figures out how to converge (create what's missing, change what differs, leave correct things alone). Because the spec is the end state, re-applying it is naturally idempotent and the tool can detect and correct drift. An imperative (or procedural) approach states how: an ordered list of commands ('create server, then install package, then edit file') that you must make safe to re-run yourself, since the script doesn't inherently know the current state. Most modern IaC and orchestration tools are declarative for exactly these reasons — idempotency, drift detection, and reproducibility — while shell-style provisioning scripts are imperative. Knowing which model a tool uses tells you how it will behave on a second run.
A DevOps team is debating whether to manage their cloud infrastructure with Terraform (a declarative IaC tool) or with a collection of imperative Bash scripts that call the cloud provider's CLI. Which statement accurately captures a fundamental difference between these two approaches?#
Options
Show answer
Declarative tools like Terraform compare recorded state against the desired configuration and apply only the differences, so re-running an already-converged configuration makes no changes. Imperative Bash scripts run a fixed command sequence with no memory of prior runs, so idempotency must be hand-coded with explicit existence checks.
The declarative approach is defined by the tool holding a model of desired state and recorded state (Terraform's state file) and computing a diff, so it only applies the delta; when the real infrastructure already matches the declaration, a rerun produces no changes, which is idempotency. Imperative Bash scripts issue a fixed sequence of commands with no memory of prior runs, so they are not idempotent by default and must add explicit existence checks to approximate the same behaviour. The statement about retrying CLI calls is wrong because retries do not make a create command safe to repeat, the statement about file order is wrong because Terraform builds a dependency graph rather than following file order, and the statement about scripts keeping a state file is wrong because plain Bash scripts have no built-in state.
In one or two sentences, describe a key difference between declarative and imperative approaches to infrastructure as code. Your answer should address how each approach relates to idempotency and to specifying the desired state versus the steps to reach it.#
Show answer
Declarative infrastructure as code lets you specify the desired end state and the tool converges to it idempotently, so applying the same configuration repeatedly produces the same result without manual guards. Imperative approaches specify the step-by-step commands needed to reach that state, so ensuring idempotency is left to the author and may require explicit checks.
The central difference is that declarative tools (e.g., Terraform, CloudFormation) describe the desired end state and reconcile toward it idempotently. Reapplying the same declaration yields the same end state because the tool diffs current state against desired state and only makes the changes needed. Imperative tools (e.g., shell scripts calling cloud APIs) encode the exact sequence of commands to reach the state; nothing inherent guarantees idempotency, so the author must add guards or conditional checks to avoid duplicating resources or re-running destructive steps. A strong answer therefore names idempotency and contrasts desired-state specification with step-by-step specification.
A team provisions AWS networking with two approaches. Assume AWS as the provider, Terraform 1.x with the AWS provider 5.x, and that Approach B declares the security group with inline ingress blocks inside a single aws_security_group resource (not separate aws_security_group_rule or aws_vpc_security_group_ingress_rule resources).#
Show answer
Terraform detects the manually added rule as drift: it refreshes the real security group, compares it with the inline ingress blocks in its configuration and state file, and its plan shows the extra rule being removed so the group matches the declared configuration. The bash script never reads existing infrastructure, so it does not notice or remove the extra rule; re-running its create calls either creates duplicate resources or fails on name or duplicate-rule conflicts, and it cannot converge the environment to the declared state.
With AWS as the provider and the security group declared using inline ingress blocks, the aws_security_group resource treats those blocks as authoritative. On the next terraform plan, Terraform refreshes the real security group, finds the console-added rule absent from its configuration and state, and plans to remove it, which is drift detection and reconciliation. The bash script has no state and no existence checks, so it never reads the security group before acting. Re-running its create calls produces duplicate resources or fails on conflicts, and the extra rule stays in place. The key difference is that the declarative tool compares actual infrastructure against desired state and corrects it, while the imperative script only replays commands and cannot see or undo out-of-band changes.
In Terraform's declarative model, a state file is maintained alongside the configuration files (.tf). Which statement correctly describes how Terraform uses the state file and real infrastructure during a default terraform plan operation (Terraform 1.x)?#
Options
Show answer
During a default terraform plan in Terraform 1.x, Terraform queries real infrastructure to refresh its in-memory view of state, then diffs that view against the configuration to propose changes. The persisted state file is not rewritten by plan; only apply (or a refresh-only apply) writes it, and resources change only when apply runs.
During a default terraform plan, Terraform reads the .tf files for the desired state and reads the state file to know which real objects it manages. It then queries the providers for the current attributes of those existing objects and holds the refreshed result in memory, without persisting it. It compares that in-memory view with the configuration and presents the differences as a proposed plan. Only apply changes real resources or writes the state file. The option claiming the state file defines desired state is wrong because the configuration defines it. The option claiming real infrastructure is queried only during apply is wrong because plan performs that refresh. The option calling state a mere cache is wrong because Terraform needs the state's mapping from resource blocks to real object IDs to plan updates rather than recreations. The option claiming no apply step is needed is wrong because plan never changes resources.
You are provisioning infrastructure for a three-tier web application. A colleague proposes replacing your team's existing imperative bash scripts (which call aws ec2 run-instances, aws ec2 create-security-group, and similar AWS CLI commands) with a Terraform configuration that declares the same resources. Consider a provisioning run that is interrupted midway: some resources were created, others were not, and the process was killed before completion. Which statement accurately describes a fundamental behavioral difference between the two approaches when you re-run the provisioning?#
Options
Show answer
On a re-run after an interrupted run, Terraform checks declared configuration against its state and real infrastructure and creates only what is missing. A plain bash script re-executes its commands from the top, which can create duplicate resources unless each step is guarded by an existence check.
Terraform's declarative model means each invocation refreshes the recorded state against the real resources, diffs that against the declared configuration, and produces a plan containing only the changes needed to converge, so an interrupted run can be re-applied. An imperative bash script executes commands sequentially, so a re-run repeats completed commands and can create duplicates or fail with 'already exists' errors unless each command has an explicit idempotency check. The other statements are wrong: neither approach provides automatic rollback or atomic all-or-nothing provisioning, and it is Terraform, not the bash script, that maintains a state file.
In a declarative IaC system like Terraform, the tool maintains a state file (terraform.tfstate) alongside the declared configuration. Explain two critical roles this state file plays that an imperative provisioning script using cloud-provider CLIs does not have, and explain how state enables drift detection.#
Show answer
The state file serves two key roles. First, it maps declared resource addresses (e.g., aws_instance.web) to real-world resource IDs (e.g., i-0abcd1234), so Terraform knows which cloud object each config block manages across runs, and it can plan updates or destroys for resources that were removed from configuration. Second, it records the last-known attribute values and dependency metadata for each managed resource, giving Terraform a baseline to diff against the desired configuration. Drift detection works because, on a normal plan, Terraform refreshes state by querying the provider for each managed resource's current attributes (this refresh can be skipped with -refresh=false), then compares the refreshed reality against the recorded state and the desired configuration. Any divergence, whether from manual console changes, out-of-band CLI edits, or other automation, appears as a planned change to bring the resource back to the desired state. An imperative script has no such address-to-ID mapping or recorded baseline; it runs discrete commands and cannot tell that a resource's current attributes differ from what an earlier run set.
The state file is what makes declarative IaC fundamentally different from imperative scripting. First, it binds declared resource addresses to real-world cloud resource IDs; without this mapping Terraform cannot know which aws_instance.web refers to which EC2 instance, nor which resources to destroy when a block is removed from configuration. Second, it records last-known attribute values and dependency metadata, giving Terraform a baseline to diff against the desired configuration. Drift detection then relies on refresh: on a normal plan Terraform queries the provider for each managed resource's current attributes and compares them with the recorded state and the desired configuration, so out-of-band changes surface as planned changes. An imperative script using the AWS CLI keeps no persistent record of what it created or what attributes those resources should have, so it cannot detect that a resource has been modified out-of-band.
Your organization manages 300+ AWS resources (VPCs, EC2 instances, RDS databases, IAM roles, S3 buckets, and load balancers) through a collection of imperative bash scripts that wrap the AWS CLI. The scripts have grown unmaintainable, lack idempotency guarantees, and frequently produce inconsistent environments. Design a migration to Terraform as a declarative IaC tool. Cover: how existing resources are brought under Terraform management without downtime or recreation, how state is stored and protected for team collaboration, how the transition period is managed while some resources are still provisioned by scripts and others by Terraform, and what ongoing guardrails prevent configuration drift from manual changes after migration.#
Show answer
I would migrate incrementally, one resource group at a time, rather than in a big-bang cutover. For each group I would write Terraform configuration describing the existing infrastructure and bring resources under management with declarative import blocks (or terraform import on older versions), mapping each address to the existing AWS ID. Importing only records the resource in state and does not edit it. I would then run terraform plan and adjust the code until the plan shows no changes. If a plan shows a replacement because the code disagrees with an immutable attribute, I would change the code to match the live resource, never the live resource to match the code. For state, I would use a remote S3 backend with versioning, encryption, and tightly scoped IAM access, with state locking enabled through use_lockfile on Terraform 1.10 or later; DynamoDB locking is deprecated, so I would not build new setups around it. I would keep separate state per environment to limit blast radius. For ordering, I would import foundational dependencies first: networking (VPCs, subnets, route tables, security groups) and IAM roles and instance profiles, then compute (EC2, Auto Scaling groups, load balancers), then data stores (RDS, S3) that depend on those subnet groups and security groups. For each group I would freeze the matching bash scripts, import, confirm a clean plan, and then retire those scripts, so no resource is managed by both systems at once. After migration, a CI pipeline would run terraform plan on every pull request and block merges that produce unexpected changes. A scheduled terraform plan -detailed-exitcode job would alert the team on drift. Manual production changes would be restricted through access controls, with an audited break-glass path for incidents so responders are never blocked.
This is an open design problem, so it is graded against a weighted rubric rather than a single keyed answer. The four criteria cover import without disruption (import blocks or terraform import, iterating code until the plan is clean, and never fixing code by changing live infrastructure), remote state with locking (current S3 native locking via use_lockfile, with DynamoDB noted as deprecated, plus encryption, versioning, and access control), dependency-ordered per-group coexistence (foundational networking and IAM imported before compute, data stores after their network dependencies, and scripts retired per group), and post-migration drift prevention (CI plan gating, scheduled detailed-exitcode drift checks, and audited break-glass access instead of an absolute ban). The sample answer covers each criterion with concrete mechanisms, and any strong design that names mechanisms for all four should earn full credit.
You manage Terraform state for a production AWS environment in an S3 bucket. Using Terraform 1.10 or later, you want state locking so two engineers cannot apply the same state at once, and you do not want to create a DynamoDB table. Name the s3 backend argument that enables this, and briefly describe what Terraform writes to the bucket to hold the lock.#
Show answer
Set use_lockfile = true in the s3 backend block. Terraform then creates a .tflock lock object alongside the state file in the same bucket, using S3 conditional writes so that only one writer can acquire it. The lock object is deleted when the operation finishes, so no DynamoDB table is needed.
Since Terraform 1.10, the S3 backend supports native state locking through the use_lockfile argument, which replaces the older DynamoDB-based approach that is now deprecated. With use_lockfile = true, Terraform writes a .tflock object next to the state object in the bucket, relying on S3 conditional writes so only one process holds the lock at a time, and it removes the object when the run ends. The correct answer is therefore the use_lockfile argument together with a description of the S3 lock file, not a DynamoDB table.
Using Terraform 1.x, a managed resource has a mutable, non-force-new argument that is explicitly set in the configuration (for example, tags) and is not listed in any lifecycle { ignore_changes } block. After the last successful apply, an out-of-band process changes that argument on the real cloud object; the object still exists. You then run terraform plan with default options and no configuration changes. Briefly name the two steps Terraform performs, in order, to obtain the prior state that it later diffs against the configuration. Then explain why the plan proposes an in-place update instead of reporting no changes.#
Show answer
First, Terraform loads the prior state from its state store (the state file or backend), recording the attributes saved after the last apply. Second, it refreshes that state by calling each provider's Read operation, which updates the recorded attributes to match the real cloud object. The plan is then computed by comparing this refreshed state with the configuration. Because the out-of-band change altered the real value of the configured argument, the refreshed value differs from the configured value, so the diff is non-empty and proposes an in-place update that restores the configured value.
With default options, a Terraform 1.x plan first loads the prior state recorded after the last apply, then refreshes it by calling each provider's Read operation so the state reflects the real cloud object. Only after these steps does Terraform compare the refreshed state with the configuration, and that comparison is the plan computation itself, not a pre-plan step. The argument is explicitly configured, not ignored, and mutable rather than force-new. The out-of-band change makes the refreshed value differ from the configured value, so the diff is non-empty and is planned as an in-place update that reverts the object to the configured value. A no-changes result would require the refreshed value to match the configuration, which the drift prevents.
You are the platform architect for a company running 40+ microservices on Kubernetes across dev, staging, and prod. The platform team manages cluster infrastructure with Terraform (declarative). Application teams deploy with a mix of Helm charts (declarative) and imperative kubectl scripts for operational tasks such as canary rollouts, emergency scaling, and manual rollbacks. Imperative actions cause drift that Helm or the GitOps controller reconciles away, and application teams resist 'pure GitOps' because it slows emergency response.#
Show answer
Separate desired state (the 'what') from runtime actions (the 'how and when') and make the boundary explicit. Declarative layer: Terraform owns cloud and cluster infrastructure (VPCs, node pools, ingress controllers, CRDs). A GitOps controller (Argo CD or Flux) owns application manifests (Helm charts, Kustomize overlays, release versions) for every environment; all desired state lives in Git, and a hand-run kubectl apply or helm install is never the source of truth. Imperative actions are allowed only when they are expressed as desired-state changes that the controller converges on: a rollback commits the previous image tag or chart revision; a canary shift updates a weight in a progressive-delivery resource; an emergency scale-up updates HPA min/max or replica count in the chart. Drift detection: the GitOps controller continuously reconciles live state against Git (for example every few minutes) and alerts on any diff; a scheduled terraform plan job (for example nightly) detects infrastructure drift from console changes and opens a PR or ticket. Emergency guardrails: time-boxed, audited break-glass RBAC lets on-call engineers mutate resources directly during an incident; every break-glass action is logged, and a post-incident Git commit encoding the permanent change is mandatory. Reconciliation can be paused per workload (pause annotation or scaling the controller down for a namespace) so it does not fight a deliberate rollout or manual fix, and the pause is itself time-limited and recorded. Ownership: the platform team owns Terraform, the GitOps controller configuration, and convergence policy; application teams own their Helm charts and release-manifest paths in Git; the SRE on-call owns the reconciliation decision during an active incident, including pausing reconciliation and owning the follow-up commit that makes the change declarative. Imperative actions are therefore temporary by construction: they buy time, and the Git commit is the durable record.
This is an open system-design question with no single correct implementation, so it stays a short answer graded against its rubric rather than a fixed key. A strong answer must (1) separate a declarative desired-state layer (Terraform for infrastructure, a GitOps controller for application manifests, all desired state in Git) from the runtime layer, and show that rollbacks, canary shifts, and emergency scaling are expressed as desired-state fields the controller converges on rather than raw mutations it fights; (2) specify automated drift detection with a defined cadence, namely continuous GitOps reconciliation plus a scheduled Terraform plan for infrastructure drift; (3) define emergency guardrails that are time-boxed, audited break-glass access, a way to pause reconciliation per workload, and a mandatory post-incident Git commit; and (4) give an ownership model that distinguishes who owns desired state (platform team for infrastructure and GitOps configuration, application teams for charts and release manifests) from who makes the runtime reconciliation decision during an incident (SRE on-call).
Terraform uses a declarative HCL DSL and applies changes through a one-shot plan-and-apply cycle that depends on an external state file tracking the resources it manages. A Kubernetes GitOps controller such as Argo CD or Flux also uses declarative manifests, but runs a continuous reconciliation loop that converges observed cluster state toward declared desired state, with Git as the source of truth. Which statement correctly describes the fundamental architectural distinction between these two paradigms?#
Options
Show answer
Terraform runs a one-shot plan-and-apply cycle that depends on an external state file, while a Kubernetes GitOps controller such as Argo CD runs a continuous reconciliation loop that converges live cluster state toward Git-declared desired state without a Terraform-style state file. Both tools remain declarative; the push or pull delivery model is orthogonal to this distinction.
Both Terraform and a GitOps controller are declarative: the engine derives the steps from a declared end state, so the option claiming Terraform is imperative is wrong, and the option saying the user writes ordered commands in both tools is wrong for the same reason. The real architectural split is execution model and state handling. Terraform performs a one-shot plan-and-apply that diffs against an external state file it depends on. A GitOps controller runs a continuous loop that re-derives drift on every iteration by comparing Git-declared desired state with the live cluster API, and it does not need a separate Terraform-style state file. The option saying a GitOps controller stores no state at all is wrong because controllers persist status inside Kubernetes (for example Argo CD Application status or Flux resource state in etcd), and Terraform does not keep its state in etcd. The push-versus-pull delivery model is orthogonal to this distinction.
Consider Terraform, a mature declarative IaC tool that maintains an explicit state file. Which of the following statements about its declarative reconciliation semantics are true? Select all that apply.#
Options
Pick every one that applies.
Show answer
Terraform creates a referenced resource before any resource that depends on it, because it builds a dependency graph from implicit references and depends_on. Separately, running terraform plan -refresh=false skips reading real infrastructure, so out-of-band changes do not appear in the plan. Block order in the file and automatic continuous reconciliation are not true.
Terraform builds a dependency graph from implicit references (such as one resource's attribute used in another) and from explicit depends_on. A resource that depends on another is created only after the one it depends on, but unrelated resources have no edge between them and may be created in parallel, so the ordering is a constraint on dependent pairs rather than a global sequence. The statement that skipping refresh hides out-of-band changes is also correct: with terraform plan -refresh=false, Terraform does not read real infrastructure back from the provider, so it compares the configuration against the stored state and changes made outside Terraform do not appear in the plan. The statement that declarative IaC removes the need for drift detection is false, because Terraform only reconciles when it is run and does not continuously enforce state. The claim that block order in the file sets creation order is false, since the dependency graph determines order and file position does not. The claim that provisioners run on every apply is false, because provisioners run when a resource is created by default (and on destroy only when when = destroy is set), not on every apply.
You run Terraform 1.10 or later and a nightly job checks each state for drift. Answer two questions: (1) What does exit code 2 from terraform plan -detailed-exitcode signify, and why is it not, by itself, proof that real infrastructure has drifted? (2) Which plan mode isolates changes made to real infrastructure outside Terraform from pending configuration edits, and what does that plan propose to do with the state? Note that the plan only proposes the state change; the state itself is not written by the plan.#
Show answer
(1) Exit code 2 means the plan ran successfully and contains pending changes (exit 0 means no changes, exit 1 means an error). Those changes can come from edited configuration as well as from out-of-band modifications, so exit code 2 alone does not prove drift. (2) terraform plan -refresh-only reads real infrastructure and proposes a state-only update that records what it finds, with no configuration changes proposed, so its output shows only drift. The state is not modified by the plan itself; it changes only if terraform apply -refresh-only is run and approved.
Exit code 2 from terraform plan -detailed-exitcode means the plan succeeded and has pending changes, and those changes may come from configuration edits as well as from modifications made outside Terraform, so the code alone cannot establish drift. terraform plan -refresh-only is the mode that isolates drift: it reads real infrastructure and proposes only a state-only update reflecting what it found, with no configuration changes. The state is not written by the plan; it is updated only when terraform apply -refresh-only is run and approved.
Your organization runs about 2,000 cloud resources across AWS and GCP. Roughly 60% were created imperatively over five years: CloudFormation stacks (including custom resources), bash scripts wrapping the AWS CLI, and manual console changes. The other 40% are already managed by Terraform. Several production RDS clusters were created manually and receive in-place schema migrations from a separate CI job. Their instance class, parameter groups, and security groups have drifted from any config file. A set of VPC peering routes must be provisioned in a strict order, or there is a brief cross-account outage. The platform team must consolidate everything under one IaC strategy within two quarters without taking production workloads offline. Design that strategy. Cover how you bring the imperatively created resources under management, where the declarative model breaks down and what escape hatches you use, how you manage drift on an ongoing basis, and how you protect the stateful RDS clusters.#
Show answer
I would make Terraform (or OpenTofu) the single declarative source of truth for long-lived infrastructure, split into stacks by cloud account, GCP project, and environment, each with its own state and remote backend. Each stack uses explicit provider configurations or aliases for its account, region, or project, so AWS and GCP resources never share one state unless they must. (1) Adoption, c1: for each resource in the imperative 60%, I first write an inventory with owner, blast radius, and dependencies. For CloudFormation-managed resources, I update the stack to set DeletionPolicy: Retain (and UpdateReplacePolicy: Retain), then delete the stack so the physical resources remain, and adopt them with declarative import blocks. I use terraform plan -generate-config-out=generated.tf to draft HCL from live state, review it, and run terraform plan until it shows no changes. CloudFormation custom resources and bash/CLI scripts are retired: each one becomes a Terraform resource or a provider-native equivalent, and any script that cannot be replaced is wrapped as a documented, gated pipeline step rather than an ad hoc run. (2) Stateful RDS, c2: I import the manually created clusters in place. I do not rebuild them. The first plan is used to match config to live state. Where an attribute is deliberately changed outside Terraform, such as a parameter group rotated by another team, I use lifecycle { ignore_changes } on exactly that attribute, so the diff is suppressed on purpose and not as a substitute for destroy protection. Every stateful resource gets lifecycle { prevent_destroy = true }, which makes Terraform refuse any plan that destroys it. Schema migrations stay in the existing CI job, which owns the schema and runs against the endpoint that Terraform outputs. Moving instance class or parameter groups under full management happens later, as a plan-verified, in-place modification in a maintenance window with a rollback plan. (3) Ordering and escape hatches, c3: I encode the peering routes with explicit references and depends_on so the graph provides the order. Where a real constraint remains, such as waiting for route propagation, I use terraform_data with triggers_replace in place of null_resource, and local-exec only as a last resort with a comment explaining why. The trigger does not start the CI job; the pipeline calls Terraform, reads the output, and then runs the migration as a gated step. (4) Drift, c4: a scheduled terraform plan -detailed-exitcode runs for every workspace. Exit code 2 is routed to alerting with the plan diff attached. Each workspace has an owning team that must either update config or revert the manual change within a set SLA, and I reduce new drift with IAM and SCP restrictions that limit console writes to production. Rollout runs stack by stack, starting with the lowest-risk stacks, and each stack is considered done only when its plan is clean and its alerting is live.
This is an open staff-level design problem, so it is graded with a weighted rubric instead of a single key. A strong answer adopts the imperative resources without recreating them, using current import blocks, -generate-config-out, and CloudFormation retention before stack removal. It treats the stateful RDS clusters as in-place adoption protected by prevent_destroy, uses ignore_changes only for deliberate out-of-band attributes, and keeps schema migrations in the CI job. It encodes the peering order with depends_on and uses terraform_data or local-exec only where the graph cannot express the constraint. It also sets up continuing drift detection with ownership, and splits state across cloud accounts and GCP projects with explicit provider configuration. The sample answer covers every criterion.
Related interview questions
Job market
See devops salaries and hiring demand from live job postings.
Practise these until they stick
That's every question we hold on this topic, and the page marks what you pick. What it can't do is remember. A free account keeps every answer, and what you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback