Infrastructure as Code and GitOps Questions
Defining and managing infrastructure and delivery state declaratively: provisioning as code (Terraform, CloudFormation, Pulumi, Ansible, Puppet), configuration management, idempotency, drift detection and remediation, and version control for infrastructure definitions, extended by GitOps where git is the source of truth for deployment and infrastructure state. Covers keeping environments consistent, treating config as a first-class versioned artifact, pull-based deployment and continuous reconciliation toward the committed state (ArgoCD, Flux, and similar controllers), Kubernetes manifest and configuration delivery via git, secrets handling for IaC and GitOps pipelines, policy-as-code guardrails (OPA, Sentinel), Terraform state management and locking, and auditable change through version control: branching strategy, pull request review, commit conventions, and code review policy for infrastructure code. Distinct from the CI/CD pipeline design topic, which owns generic pipeline structure and platform-scale release orchestration (build, test, artifact publishing, runner mechanics) and the architectural choice between push-based CI/CD and pull-based GitOps, even when the payload is infrastructure code. Distinct from the safe deployment and rollback strategies topic, which owns deployment-strategy mechanics: canary and blue-green traffic shifting, automated rollback triggered by metrics or SLOs, feature-flag progressive delivery, Kubernetes rollout mechanics (maxSurge, maxUnavailable, health-check gating), and database or schema migration safety as it gates a release, even when the delivery mechanism is GitOps. Distinct from the automation and scripting topic, which owns operational-scripting disciplines (retry and backoff logic, CLI tool design, generic file, checksum, or diff utilities) when the task is not specifically about declarative infrastructure or configuration state. This topic keeps the GitOps reconciliation loop itself, drift detection and remediation, and IaC state and module lifecycle management regardless of which adjacent discipline a question also touches.
Compare Argo CD and Flux as GitOps controllers. Focus on architecture (pull vs push, UI presence), reconciliation model, multi-cluster support, extensibility, and example use-cases where one might be preferred over the other.
Sample Answer
Direct answer
Argo CD is PULL-based with a first-class web UI: an in-cluster (or centrally-hosted) controller polls/watches Git and reconciles state, and its UI is a core, heavily-used part of the product for visualizing application health, sync status, and diffs. Flux is ALSO pull-based (both tools use the pull model that defines GitOps, an in-cluster agent reconciling toward Git, not a CI pipeline pushing kubectl apply), but Flux has historically been UI-LESS by design (a set of Kubernetes-native controllers and CRDs (custom resource definitions), composable with flux CLI and optionally a separate UI product, Weave GitOps, rather than a built-in dashboard); the real architectural distinction between them is less "push vs pull" (both pull) and more UI-centricity, extensibility model, and multi-cluster management approach.
Structured elaboration
Architecture and reconciliation model. Both tools run an in-cluster (or hub-cluster) controller that watches a Git source and reconciles the cluster's actual state toward it, the defining GitOps pull pattern. Argo CD's application-controller compares each Application CRD's live state against its Git-sourced desired state on a poll/watch interval and can auto-sync or wait for manual sync. Flux's toolkit is composed of several purpose-specific controllers (source-controller watching Git/Helm/OCI sources, kustomize-controller and helm-controller applying the resulting manifests, notification-controller for alerting) communicating via Kubernetes CRDs, a more Unix-philosophy, composable design versus Argo CD's more monolithic (though still modular internally) application model.
UI presence. Argo CD's UI is a primary, widely-relied-upon interface: application topology visualization, live sync-status and health, diff view before syncing, and manual sync/rollback actions performed directly through it. Flux is designed to be operated primarily via kubectl/flux CLI and GitOps itself (changes go through Git, not a UI); Weave GitOps (and other third-party dashboards) can be layered on for visualization, but it is an add-on, not baked into the core toolkit the way Argo CD's UI is.
Multi-cluster support. Argo CD's typical pattern is a SINGLE (or small number of) hub instance managing many registered target clusters via cluster credentials stored centrally, giving one place to see everything across the fleet. Flux's typical pattern is per-cluster (or per-cluster-group) installation, each cluster running its own Flux controllers watching its own (or a shared) Git source; multi-cluster fleets are usually composed via Flux's Kustomization dependency ordering and a shared source repo rather than a single central controller instance. This is a genuine architectural fork: Argo CD centralizes visibility and control, Flux distributes it, each with corresponding operational trade-offs (a central Argo CD instance is a single higher-value target and a potential bottleneck; distributed Flux installations avoid that single point but lose the single-pane-of-glass view without additional tooling).
Extensibility. Argo CD extends via Config Management Plugins (custom manifest generation tools beyond Helm/Kustomize/plain YAML) and Argo CD Notifications/Argo Rollouts as companion projects. Flux extends via its CRD-based controller composition (adding a new source type or a new applier is architecturally closer to adding a new controller to the toolkit) and integrates natively with Flagger for progressive delivery.
Worked example
When Argo CD tends to be preferred: an organization wants a SINGLE central dashboard across dozens of clusters for platform-team visibility, non-GitOps-fluent stakeholders (engineering managers, on-call responders) who need a UI to check deployment status without learning kubectl/flux commands, and out-of-the-box multi-cluster fleet management from one control point.
When Flux tends to be preferred: a Kubernetes-native, CLI/CRD-first team that wants each cluster fully self-sufficient (no dependency on a central controller instance being reachable, which matters for edge or air-gapped clusters), tight composability with other CNCF toolkit pieces (Flagger for progressive delivery, notification-controller for lightweight native alerting), and a philosophy of "the CRDs and Git ARE the interface" with no expectation of a built-in dashboard.
Trade-offs and pitfalls
- Common mistake: describing this comparison as "push vs pull." Both tools are pull-based; this is the single most common factual error in comparing them, and stating it correctly (both pull, differing mainly in UI-centricity, controller composition, and multi-cluster topology) is itself a signal of genuine familiarity with the tools rather than a surface-level comparison.
- A single central Argo CD hub instance is both its biggest UX advantage and its biggest operational risk: losing that instance (or its access to target-cluster credentials) affects visibility and control across the entire fleet at once, a concentration-of-risk trade-off distributed Flux installations avoid by design, at the cost of needing separate tooling for fleet-wide visibility.
- Common mistake: assuming Flux's lack of a built-in UI means it is less mature or less capable. The absence is a deliberate design choice (CLI/CRD/Git as the primary interface), not a capability gap; teams that prioritize a rich UI experience should weigh that as a genuine feature difference, not treat Flux as behind on a roadmap item it deliberately chose not to prioritize the same way.
- Neither tool's multi-cluster model is strictly superior; centralized (Argo CD-style) visibility trades against distributed (Flux-style) independence and blast-radius isolation, and the right choice depends on whether the organization values single-pane-of-glass control more than fleet-wide resilience to a single control-plane instance's availability.
Define infrastructure-as-code (IaC) drift. Explain how you would detect drift across multiple environments at scale, and describe remediation approaches (reapply, import, destroy/recreate) and guardrails you would put in place to prevent accidental manual changes.
Sample Answer
Direct answer
Infrastructure-as-code (IaC) drift is the gap between the DECLARED state a Terraform/CloudFormation/Ansible configuration specifies and the ACTUAL live state of the resources it manages, opening whenever something changes the real infrastructure through a path OTHER than the normal apply pipeline: a manual console edit, an emergency fix, an out-of-band automated process, or a resource's own natural drift (a certificate auto-renewing, a value the provider itself changes). At scale, across multiple environments, drift needs to be detected on a SCHEDULE (not just discovered accidentally the next time someone happens to run plan), and remediated by one of three genuinely different mechanisms depending on WHAT drifted: reapply (push declared state back over the drift), import (accept the live state and update the declaration to match it), or destroy/recreate (for drift that cannot be reconciled in place).
Structured elaboration
Detecting drift across multiple environments at scale. A scheduled job (not developer-triggered) running terraform plan (with no apply) against EVERY environment's state on a regular cadence, parsing the plan output specifically for changes that are NOT expected (a plan showing "no changes" is healthy; any diff signals drift), and reporting results centrally rather than requiring someone to manually check each environment. At real scale (many workspaces/environments), this needs to run in PARALLEL with rate-limiting and credential-error handling against the underlying cloud APIs, and results need to be aggregated into one dashboard/report rather than scattered across individual CI job logs nobody is checking regularly.
Remediation approach 1, reapply. For drift where the DECLARED state is correct and should simply be restored: run terraform apply to push the declared configuration back over the live drift. Appropriate when the drift was an unauthorized or accidental change and the Git-declared state genuinely represents the intended configuration.
Remediation approach 2, import. For drift where the LIVE state turns out to be the one that should actually be considered correct (a legitimate emergency change that should be formalized, not reverted): update the Terraform CONFIGURATION to match what is actually running, so the next plan shows no diff, rather than fighting a change that was correct. This is the remediation path for "the live state is right, Git needs to catch up," the mirror image of reapply.
Remediation approach 3, destroy and recreate. For drift that cannot be reconciled in EITHER direction cleanly (a resource modified in a way that makes its current state genuinely incompatible with continued management, or drift combined with a provider limitation that prevents importing the change cleanly): destroy the drifted resource and recreate it fresh from the declared configuration. Highest-risk of the three (real downtime/data-loss potential for a stateful resource), reserved for cases the other two approaches cannot cleanly resolve.
Guardrails to prevent accidental manual changes. IAM (identity and access management) policy restricting WHO can make direct changes to managed resources outside the pipeline's own service identity (the strongest structural guardrail, prevention rather than detection); a documented, enforced policy that any necessary emergency change goes through a bounded, audited emergency-change exception with mandatory reconciliation back into Git; and, as a detection-layer backstop for whatever prevention does not catch, the scheduled drift-detection job above, since prevention alone is never perfectly complete in practice.
Trade-offs and pitfalls
- Common mistake: treating "reapply" as the default remediation for every drift, without first checking whether the LIVE state might actually be the one that should be kept. A drift caused by a legitimate, already-deployed emergency fix should be IMPORTED (formalized into the declaration), not silently reverted by a reflexive reapply; choosing the wrong direction for a specific drift event can undo a real fix.
- Destroy-and-recreate is the highest-risk remediation and should never be the DEFAULT choice for ordinary drift, it is appropriate only when the other two genuinely do not apply; a scheduled drift-remediation process that defaults to destroy/recreate for anything it cannot cleanly reapply risks real, avoidable disruption for drift that a careful import would have resolved safely.
- Scheduled drift detection at real scale needs its OWN rate-limiting and credential-handling discipline, running
planagainst every environment on a fixed schedule without staggering or backoff can itself trigger cloud-provider API throttling, ironically causing the detection job's OWN failures to look like (or mask) real drift if not handled distinctly. - IAM-based prevention is the stronger guardrail but is never complete on its own, break-glass access, third-party integrations with their own write permissions, and provider-side automatic changes (certificate rotation, for instance) all sit outside what IAM restriction alone can prevent; detection remains necessary even with strong prevention in place, not a redundant afterthought.
Compare versioning strategies for configuration and artifact management across an enterprise: semantic versioning, timestamped builds, git-commit-hash references, and artifact-repository versions. Recommend a strategy that balances traceability, ability to rollback, and support for reproducible deployments.
Sample Answer
Direct answer
The four versioning strategies answer different questions, and conflating them is the core mistake this comparison exists to prevent: semantic versioning (semver) communicates INTENT (is this change breaking, additive, or a fix), a timestamped build communicates WHEN something was built, a Git commit-hash reference communicates EXACTLY WHAT SOURCE produced it with zero ambiguity, and an artifact-repository version communicates WHERE a specific, retrievable build lives. A strategy balancing traceability, rollback, and reproducibility for most organizations layers them: semver for human-facing communication of risk, backed by a commit-hash reference as the actual, unambiguous pointer to source, resolved through an artifact repository as the retrieval mechanism, with a timestamp as supplementary metadata rather than the primary identifier.
Structured elaboration
Semantic versioning. Strong at communicating RISK to a human or an automated update-policy decision, weak as a STANDALONE identifier for reproducibility, since v2.3.0 alone does not tell you the exact commit that produced it without a separate tag-to-commit mapping (which Git itself maintains, but only if tags are used correctly and never force-moved).
Timestamped builds. Strong at answering "when was this built" and useful for retention/cleanup policies, but WEAK for both traceability (a timestamp alone says nothing about what changed) and reproducibility (two builds from the same source at different times might be identical or might differ, the timestamp alone cannot tell you which).
Git commit-hash references. The STRONGEST for reproducibility and precise traceability, a commit hash is a cryptographic, unambiguous pointer to an EXACT source state, no interpretation or trust in a separate mapping required. Weakest for HUMAN communication, a 40-character hash conveys no information about risk or intent the way a semver tag does, nobody scans git log for hashes to understand what changed.
Artifact-repository versions. Strong for RETRIEVAL (a build artifact needs to live somewhere retrievable, and the artifact repository's own versioning scheme, often itself semver-or-timestamp-based, is how consumers actually fetch a specific build), but the artifact repository's version is only as trustworthy as the LINK it maintains back to the source commit that produced it, if that link breaks or was never recorded, the artifact becomes untraceable to its origin even though it is perfectly retrievable.
Worked example
A concrete layered scheme for a Terraform module release, combining all four appropriately:
- Source of truth: the Git commit hash. Every release is, underneath everything else, a specific commit; this is the only thing that is UNAMBIGUOUSLY reproducible.
- Human-facing label: a semver tag (
v2.3.0) pointing at that exact commit, giving consumers a risk-communicating name to reference in changelogs, PRs, and conversation. - Retrieval mechanism: the artifact/module registry entry, published under the SAME
v2.3.0label, resolving to a specific, retrievable build artifact (or, for a source-only module, the tagged Git reference itself). - Supplementary metadata: a build timestamp recorded alongside the artifact (in its own metadata, not as the primary identifier), useful for retention policies and for answering "how old is what's currently deployed" without being relied on for reproducibility or traceability, which the commit hash and semver tag together already provide more reliably.
A consumer's own configuration references v2.3.0 (the human-meaningful label); tooling resolves that to the specific commit hash and artifact it points to (the reproducibility guarantee); and the timestamp is available for observability/reporting but never load-bearing for identifying WHAT is actually running.
Trade-offs and pitfalls
- Common mistake: using a semver tag as though it were, by itself, a reproducibility guarantee, without verifying (or enforcing) that the tag is immutable once cut. A tag that CAN be force-moved to point at a different commit later (a real risk if tag-protection is not enforced on the Git hosting platform) silently breaks the entire chain of trust every consumer pinned to that tag is relying on; tag immutability needs to be a structurally enforced property (branch/tag protection rules), not an assumed convention.
- Timestamped builds alone, with no semver or commit-hash reference, are a common anti-pattern in organizations that have not yet adopted a real versioning discipline, they FEEL like versioning (each build has a unique-looking identifier) while providing neither the risk communication of semver nor the unambiguous reproducibility of a commit hash.
- An artifact repository's own version scheme diverging from the underlying source's versioning (the artifact repo using build numbers while the source uses semver, with no recorded mapping between them) is a real, common source of "we can retrieve the artifact but can't tell what source produced it," a genuine traceability gap that a layered, consistently-labeled scheme (as in the worked example) exists specifically to close.
- Reproducibility, traceability, and rollback capability are three genuinely different properties, and a strategy relying on only ONE of the four versioning mechanisms typically satisfies at most one or two of them well, the recommendation to layer all four is not redundancy for its own sake, it is covering three distinct requirements the question itself names, each of which a single mechanism alone tends to satisfy only partially.
Explain the concepts of convergence and eventual consistency in configuration management. Provide a concrete example of a converge-loop (reconciliation) system and describe failure modes where convergence may never be achieved. Suggest mitigations for those failure modes.
Sample Answer
Direct answer
Convergence is the property that a system, given a fixed desired state and enough reconciliation cycles, will reach a state that MATCHES that desired state and then stop changing; eventual consistency is the weaker, related guarantee that if updates stop arriving, all observers will EVENTUALLY see the same value, without a bound on how long "eventually" takes. A converge-loop system (any GitOps controller, or a Kubernetes controller generally) combines both: it is eventually consistent in how the cluster's observed state settles after a change, and it is CONVERGENT in the stronger sense that its target (Git-declared desired state) is fixed and known, not merely "whatever the last writer said."
Structured elaboration
Concrete converge-loop example. Argo CD's reconciliation loop: on each cycle, it computes a diff between the live cluster and the Git-declared manifest, applies the difference, and re-checks. If nothing else is changing the cluster concurrently, this loop converges: the diff shrinks to nothing and stays there. If the loop runs again on an already-converged system, it does no work, this idempotent "no-op when already matching" behavior is itself a requirement for convergence to be a meaningful, stable end state rather than an accidental one-time alignment.
Failure modes where convergence may never be achieved.
- A conflicting external actor continuously undoes the reconciler's work (a separate automation, or a human, repeatedly reverting the exact field the reconciler is trying to set); the loop keeps correcting, the external actor keeps un-correcting, and the system oscillates indefinitely rather than settling.
- The desired state itself is invalid or unsatisfiable (a manifest requesting a resource quantity the cluster cannot schedule, or two declared resources with a genuine, unresolvable dependency cycle); the reconciler cannot converge to something that cannot exist, and without an explicit failure signal, it may simply retry forever.
- A transient dependency never becomes available (waiting on a resource that some OTHER, un-reconciled system is supposed to create, a manually-provisioned prerequisite that was never actually done); the loop is technically doing everything correctly but is blocked on an external precondition outside its own control.
- Reconciliation itself has a bug that makes each pass compute a slightly different "desired" outcome (non-deterministic ordering in how a diff is computed, or a template that renders differently depending on unrelated cluster state); each cycle "succeeds" at applying SOMETHING, but that something keeps changing, so the system never settles on one final state.
Mitigations for each.
- For a conflicting external actor: identify and eliminate the other write path (this is exactly the discipline behind Git-as-sole-source-of-truth); if the other actor is legitimate, its intent needs to be captured in the SAME desired-state definition the reconciler reads, not left to fight over the live object out-of-band.
- For an unsatisfiable desired state: validate BEFORE applying (a policy-as-code check, a schema validator, a dry-run) so an impossible desired state is rejected at PR time rather than discovered as an infinitely-retrying reconciler in production; and bound retries with backoff plus an alert after N consecutive failed attempts, so a genuinely stuck reconciliation surfaces to a human instead of looping silently forever.
- For a blocked external dependency: make the dependency EXPLICIT and reconciled by the SAME system where possible (bring the manual prerequisite under the same declarative management), or add an explicit readiness/precondition check the reconciler can report on clearly rather than retrying blindly.
- For non-deterministic reconciliation: pin every source of variability (sort collections before diffing, use content-addressed references like image digests rather than resolved-at-apply-time values) so the SAME desired state always produces the SAME computed diff.
Trade-offs and pitfalls
- Common mistake: treating "the reconciler is still running" as evidence it is making progress. A reconciler stuck in the conflicting-external-actor failure mode is BUSY (constantly reapplying) but never converging; the useful signal is not "is it running" but "is the size of the diff between live and desired state trending toward zero and staying there," which needs to be an EXPLICIT metric, not inferred from activity level.
- Bounding retries with backoff-and-alert is a mitigation for VISIBILITY, not a fix for the underlying cause. An alert after repeated failed reconciliation tells a human where to look; it does not itself resolve an unsatisfiable desired state or a fighting external actor, both of which need a human or a process change, not a tighter retry loop.
- Eventual consistency's lack of a time bound is a real, not just theoretical, operational risk. A system that is technically guaranteed to converge "eventually" but takes hours to do so under a specific failure pattern can still cause a real incident if nothing alerts on convergence taking longer than expected; "will eventually converge" and "converges fast enough to matter" are different claims, and only the metric-based bound (not the theoretical guarantee) tells you which one you actually have.
Design a delegated self-service model for teams to request and approve infrastructure changes while maintaining central controls. Explain repository permissions, approval flows, policy-as-code enforcement, sandbox environments, and how audit trails and rollback capabilities are preserved.
Sample Answer
Direct answer
A delegated self-service model has to separate two things a naive design conflates: WHO can request/approve a change (which should genuinely delegate to the requesting team, that is the entire point of self-service) and WHAT that change is allowed to touch (which stays centrally controlled via policy-as-code and repository permissions, regardless of who is requesting). Self-service without that separation either becomes ungoverned (anyone can do anything, defeating central control) or becomes fake self-service (every request still routes through a central team for approval, defeating the actual point of delegating).
Structured elaboration
Repository permissions. A shared repo with path-scoped CODEOWNERS: teams get WRITE access (via PR) to their own scoped directory, and the PLATFORM team retains sole write access to shared modules and policy definitions; self-service means a team can propose and, within their own scope, approve their OWN changes, not that they have unrestricted repository access.
Approval flows. Two tiers: requests that STAY WITHIN a team's pre-approved policy boundary (a resource size within an approved range, a resource type on an approved list) can be approved by the REQUESTING team's own designated approvers, genuine self-service; requests that fall OUTSIDE that boundary (a new resource type never used before, a size beyond the pre-approved range) route to the platform team for a one-time, ADDITIONAL review, after which, if approved, that specific pattern can be added to the team's own pre-approved boundary for future self-service use, so the platform team's involvement narrows over time rather than being a permanent bottleneck for every request of that type.
Policy-as-code enforcement. The PRE-APPROVED BOUNDARY itself is expressed as policy (an OPA/Sentinel policy defining, per team, what resource types/sizes/configurations are within their self-service scope), evaluated automatically on every PR; this is the mechanism that makes "self-service within a boundary" enforceable rather than merely a documented expectation a team could accidentally or deliberately exceed.
Sandbox environments. A genuinely SEPARATE, low-stakes environment (per-team or shared-but-isolated) where a team can experiment and validate a change BEFORE it goes anywhere near a real approval flow, reducing how often a request reaches even the self-service approval step already broken or obviously wrong, and giving the requesting team fast, independent iteration without needing anyone else's involvement at all for the exploratory phase.
How audit trails and rollback capabilities are preserved. Because delegation happens entirely through the SAME Git-PR-and-policy-as-code mechanism as any other change (not a separate, informal self-service tool bypassing normal infrastructure workflow), every self-service change is a normal, fully-audited commit; rollback is the same Git-revert-and-reconcile mechanism any other change uses, unaffected by WHO originally approved the change.
Worked example
A concrete self-service flow for a team requesting a new S3 bucket:
- Team opens a PR in their own scoped directory declaring the new bucket, using the platform team's PRE-APPROVED module for S3 buckets (which already encodes required settings: encryption, tagging, a size/retention policy within an approved range).
- Policy-as-code evaluates the PR: since the request uses the pre-approved module within its parameter bounds, it is WITHIN the team's self-service scope.
- The requesting team's own designated approver reviews and approves, no platform-team involvement required for this specific, in-bounds request.
- CI applies, using credentials scoped to that team's own resources, per the multi-tenant access-control model.
- A LATER request from the same team for a bucket configuration outside the pre-approved parameters (a much larger retention window, for instance) fails the policy-as-code check for self-service eligibility and routes to the platform team for one-time review; if approved, the platform team updates the pre-approved module's parameter bounds so future requests of this same shape become self-service too.
Trade-offs and pitfalls
- Common mistake: building "self-service" as a separate tool or portal outside the normal Git-PR workflow, which usually means it does NOT inherit the audit trail, review discipline, and rollback mechanism ordinary Git-based infrastructure changes get for free; keeping self-service INSIDE the same Git-and-policy-as-code mechanism, just with delegated approval authority within a scoped boundary, is what preserves those properties without extra, parallel tooling to build and maintain.
- A pre-approved boundary that never expands stays a bottleneck disguised as self-service, every request even slightly outside the ORIGINAL boundary routes to the platform team forever; the worked example's last step (updating the boundary after a one-time review) is what keeps self-service actually scaling over time rather than plateauing at whatever the initial policy happened to allow.
- A sandbox environment that is not GENUINELY isolated (shares any real infrastructure or credentials with production) provides a false sense of safety, a team experimenting in a sandbox they believe is isolated, when it is not, can cause real damage while under the impression they are in a safe, disposable space; the isolation needs to be structurally real, not just labeled as a sandbox.
- Central controls (policy-as-code, module curation) need their own maintenance discipline, a pre-approved module or policy that goes stale (missing a security update the rest of the org has adopted) silently becomes the weakest link in an otherwise well-governed self-service system, since teams building on it inherit whatever gap it has without necessarily knowing to check.
Unlock Full Question Bank
Get access to all Infrastructure as Code and GitOps interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.