📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is infrastructure as code, and why does click-ops in the Azure Portal fail as a team grows? Explain declarative versus imperative IaC, idempotency and drift, and how IaC changes go through pull requests and pipelines like application code.

Covers what infrastructure as code is, declarative versus imperative tools, idempotency, drift, environment parity and the pull-request workflow for infrastructure, compared with manual portal changes.

Junior Theory Beginner azure bicep devops drift infrastructure-as-code terraform

🎯 Key points

  • IaC = infrastructure described in version-controlled files, applied by a tool, not by hand
  • Declarative (Bicep, ARM, Terraform) describes desired state; imperative (az CLI scripts) lists steps
  • Idempotent: running the same template twice produces no further changes
  • Click-ops causes snowflake environments, no audit trail and no repeatable disaster recovery
  • Drift = real resources differ from code; detect with what-if / terraform plan
  • Infra changes go through CI/CD: PR with what-if or plan, then a pipeline identity (OIDC, least privilege) applies them
  • Same template plus per-environment parameters gives dev, test and prod parity
  • Rollback = redeploy the previous template version from Git; deletes and data need backups, locks and expand-contract ordering with app releases

⏱ 30-second answer

Infrastructure as code (IaC) means the cloud resources an app needs (App Service, Azure SQL, Key Vault, role assignments) are described in version-controlled files and created by a tool such as Bicep or Terraform, not by clicking in the portal. Good IaC is declarative (you describe the desired end state and the tool works out the API calls) and idempotent (running it again changes nothing if nothing changed). That gives you repeatable environments, a reviewable history in Git, and a way to rebuild after a disaster.

  • Click-ops creates snowflake environments, forgotten settings and no audit of why.
  • Drift is when reality no longer matches the code; what-if or terraform plan shows it.

The trade-off: IaC costs learning time and discipline (no more "quick fixes" in the portal), but it is the only way to keep more than one environment consistent.

🗣 Full answer (senior)

How I would answer this in an interview

"Infrastructure as code means we describe our cloud resources in files that live in Git next to the application, and a tool turns those files into real resources. On Azure that is usually Bicep, which compiles to ARM JSON and is sent to Azure Resource Manager, or Terraform with the azurerm provider. The important property is that it is declarative: I write 'there is a Key Vault with RBAC enabled and purge protection on', not 'run these five CLI commands'. The tool compares that desired state with what exists and only makes the difference, so running it twice is idempotent.

Click-ops works for one developer and one environment. It falls apart when you have dev, test and prod, three teams and an auditor. Nobody remembers that someone turned on 'Allow Azure services' on the SQL firewall in prod, so test behaves differently. There is no pull request explaining why a setting changed, and if a region has a bad day you cannot rebuild the environment from memory. With IaC the same template plus a parameter file per environment gives you parity, a Git history of every change, and disaster recovery that is a pipeline run.

The workflow is the same as for code: a branch, a pull request with the what-if or plan output attached, review, and then a pipeline identity applies it, ideally using OIDC federation and only the RBAC it needs. The mistake I see is teams that adopt Bicep but keep fixing things in the portal 'just this once'. That is drift, and the next deployment either silently reverts the fix or surprises you. IaC only pays off if the code is the single source of truth."


Declarative vs imperative

Style Example You describe Re-run behaviour
Declarative Bicep, ARM JSON, Terraform, OpenTofu The end state Converges; no change if nothing changed
Imperative az CLI or PowerShell scripts The steps May fail ("already exists") or duplicate
General-purpose code, declarative engine Pulumi (C#, TypeScript) End state, built with loops and classes Converges like Terraform

Click-ops vs IaC

Concern Click-ops IaC
Repeatability Depends on memory and wiki pages Same template, any environment
Review None, or a change ticket Pull request with what-if / plan output
Audit Activity Log says who, not why Git history says who, what and why
Disaster recovery Rebuild by hand under pressure Re-run the pipeline into Australia Southeast
Drift Invisible Shown by what-if / terraform plan

When IaC is not worth it yet

Situation Reasonable choice
A throwaway spike in a sandbox subscription Portal is fine; delete the resource group after
Learning what settings a service has Click it once, then export or write the Bicep
Anything shared, long-lived or in production Always IaC

Production example

A typical case: a team with three environments created by hand finds their test SQL database on a different service tier and with different firewall rules from prod, so a performance test passes and prod falls over. After moving to one Bicep template with three .bicepparam files, a new environment takes about 15 minutes to create from a pipeline instead of two days of tickets, and every difference between environments is a visible parameter.

🔍 What the interviewer is checking

Checks that the candidate understands why IaC exists (repeatability, review, recovery), not just that it is "scripts for the cloud".

Green flags

  • Explains declarative and idempotent in their own words
  • Mentions drift and how to detect it (what-if, plan)
  • Describes PR review with a preview and a pipeline identity applying changes
  • Uses one template with per-environment parameters

Red flags

  • Thinks exporting the portal template is IaC
  • No idea what happens when someone changes a resource by hand
  • Pipeline or developers deploy to prod with Owner rights and stored secrets

📚 Learn in depth

1. What actually happens when IaC runs

On Azure everything goes through Azure Resource Manager (ARM), a REST API. The portal, az CLI, Bicep and Terraform are all clients of it.

main.bicep ──bicep build──► ARM JSON ──PUT deployment──► Azure Resource Manager ──► resource providers
                                                          (Microsoft.Web, Microsoft.Sql, ...)

main.tf ──terraform plan/apply──► azurerm provider ──REST calls──► Azure Resource Manager
             ▲
             └── state file (what Terraform thinks it manages)

The two tools track state differently, and the difference matters:

  • Bicep / ARM does not keep a separate state file that you store and lock. ARM itself holds the live resource state, plus a deployment history per resource group (each deployment records the template, parameters and outcome). A normal (incremental) deployment compares the template with the live resources named in it and leaves anything else alone. If you want ARM to track which resources a template owns, so it can delete or detach the ones you remove, you use a deployment stack, which is effectively managed state kept by Azure.
  • Terraform keeps a state file that maps each resource address (azurerm_key_vault.main) to a real Azure resource ID. It compares code, state and reality, so the state file must be stored remotely (an Azure Storage container with locking) and protected, because it can contain sensitive values.

2. Declarative and idempotent

A declarative tool takes desired state D and current state C and computes a diff. Applying the diff gives D. Applying again finds no diff. That is idempotency, and it is what makes IaC safe to run on every merge. An imperative script such as az keyvault create ... has no diff step: on the second run it either errors or tries to change things it should not.

3. Drift

Drift happens when someone changes a resource outside the code (the portal, a CLI one-liner, an Azure Policy remediation). Consequences:

  • The next deployment may silently revert the manual fix.
  • Or the code no longer describes reality, so a rebuild produces a different environment.

You detect drift with az deployment group what-if (Bicep) or terraform plan / terraform plan -refresh-only (Terraform), ideally on a schedule. You prevent it with RBAC: humans get Reader in production, and only the pipeline identity can write.

4. Parameters and environment parity

One template, many parameter files:

infra/
  main.bicep
  modules/ (keyvault.bicep, sql.bicep, containerapp.bicep)
  env/
    dev.bicepparam   (small SKUs, public access)
    prod.bicepparam  (zone redundancy, private endpoints)

The differences between environments are now explicit, reviewable values instead of forgotten clicks.

5. The delivery workflow (CI/CD for infrastructure)

feature branch ─► PR ─► CI: bicep lint / build, what-if against test ─► review
                     ─► merge ─► deploy test ─► what-if prod ─► approval ─► deploy prod

The pipeline authenticates with OIDC workload identity federation (no stored client secret) and its service principal only has the roles it needs on the target resource groups. Templates are versioned with the app (same repo or a tagged module registry), so every release knows which infrastructure version it expects.

6. Rollback and ordering with app changes

  • Additive changes (a new app setting, a new queue) roll back by redeploying the previous template, or by simply leaving the unused resource in place.
  • Destructive changes (deletes, renames, SKU downgrades) do not roll back cleanly: recreating a deleted SQL database gives you an empty one. Protect stateful resources with CanNotDelete locks, soft delete and backups, and require approval for any plan that deletes.
  • Order: infrastructure first and backwards compatible, then the app, then remove what the old app needed (expand, migrate, contract). That keeps both app versions deployable during a rollback.

Try it yourself

  1. Create a resource group and a storage account in the portal, then run az group export and compare the generated template with what you would write by hand.
  2. Write a 15-line main.bicep with a storage account, deploy it twice with az deployment group create, and confirm the second run changes nothing.
  3. Change the storage account's minimum TLS version in the portal, then run az deployment group what-if and read the drift it reports.
  4. Add a dev.bicepparam and a prod.bicepparam that differ only in SKU and deploy both.
  5. Look at the resource group's Deployments blade and find the template and parameters of your last run.

💻 Code

A minimal Bicep file and the commands that preview and apply it. The same file serves every environment through parameters.

// main.bicep: one storage account, configured the same way everywhere
@allowed([ 'dev', 'test', 'prod' ])
param environmentName string
param location string = resourceGroup().location // e.g. australiaeast

resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  // uniqueString keeps the global name unique but stable between runs (idempotent)
  name: 'st${environmentName}${uniqueString(resourceGroup().id)}'
  location: location
  sku: { name: environmentName == 'prod' ? 'Standard_ZRS' : 'Standard_LRS' }
  kind: 'StorageV2'
  properties: {
    minimumTlsVersion: 'TLS1_2'
    allowBlobPublicAccess: false
    allowSharedKeyAccess: false // apps use managed identity, not account keys
  }
}

output blobEndpoint string = storage.properties.primaryEndpoints.blob
// env/prod.bicepparam
using '../main.bicep'
param environmentName = 'prod'
# Preview first: shows create / modify / delete, and any drift from the portal
az deployment group what-if \
  --resource-group rg-orders-prod \
  --template-file main.bicep \
  --parameters env/prod.bicepparam

# Apply (in a pipeline, after review). Running it again makes no changes.
az deployment group create \
  --resource-group rg-orders-prod \
  --template-file main.bicep \
  --parameters env/prod.bicepparam

⚠ Common mistakes

  • Mistake: Treating IaC as a one-off export of the portal. Why it is wrong: Exported templates are noisy, hard-code IDs and are never re-applied, so they rot. Instead: Write clean templates, deploy them from a pipeline and keep deploying them.
  • Mistake: Making "quick fixes" in the portal after adopting IaC. Why it is wrong: It creates drift; the next deployment reverts the fix or the code no longer describes reality. Instead: Fix it in code, or if you must hot-fix, raise a PR to match within the day.
  • Mistake: Writing imperative az scripts and calling it IaC. Why it is wrong: Scripts are not idempotent and cannot preview changes. Instead: Use a declarative tool (Bicep, Terraform) and keep scripts for glue such as data seeding.
  • Mistake: Copy-pasting a template per environment. Why it is wrong: The copies diverge exactly like click-ops environments. Instead: One template, one parameter file per environment.
  • Mistake: Applying without a preview. Why it is wrong: Renaming a resource or changing an immutable property (a storage account name, a SQL server name, a Terraform ForceNew attribute) makes the tool delete and recreate it. For a database or storage account that is a production outage and possibly data loss, and it can hide in a long diff. Instead: Always run what-if or terraform plan, attach it to the PR, and make the pipeline fail or require extra approval when the plan contains any delete or replace.
  • Mistake: Giving the pipeline Owner on the subscription. Why it is wrong: A compromised pipeline can then do anything, including granting itself more access. Instead: Scope a federated identity to the resource groups it deploys, with Contributor plus only the role-assignment rights it needs.
  • Mistake: Putting secrets in parameter files committed to Git. Why it is wrong: They end up in history forever. Instead: Use managed identity, or Key Vault references and @secure() parameters supplied at deploy time.
  • Mistake: Assuming "revert the commit" always rolls back infrastructure. Why it is wrong: Re-deploying an old template recreates a deleted resource empty; it does not bring data back. Instead: Protect stateful resources (locks, soft delete, backups) and change infrastructure ahead of the app (expand first, remove later).

🏛 Senior insight: trade-offs

The value of IaC is not the syntax, it is the operating model: the code is the only way changes reach production, every change is reviewed with a preview, and humans have read-only access to prod. Without that last part, a team gets the cost of IaC (learning, slower one-off changes) and none of the benefit, because drift creeps back in.

Start where it pays most: shared, long-lived and production resources, plus anything security-sensitive (role assignments, network rules, Key Vault settings). Infrastructure changes ride the same CI/CD path as the app, but ahead of it: add the new queue or setting first, ship the code that uses it, and remove the old resource in a later release, so either version of the app can run and rollback is a redeploy of the previous Git tag.

Measure the impact over months, not just on day one: time to create a new environment, the number of drift findings from a scheduled what-if or plan (should trend to zero), the change failure rate and incident count caused by configuration differences between environments, and mean time to recover when a region or resource group has to be rebuilt.

Option When it fits Cost When not to
Portal Learning a service, sandbox spikes Zero up front, high later Anything shared or in production
Imperative az scripts Glue steps, data seeding, one-off migrations Low, but not idempotent Defining long-lived resources
Declarative IaC (Bicep / Terraform) Every real environment Learning curve, pipeline setup Throwaway experiments

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions deploying IaC from a pipeline. Why: Checks the candidate can wire infrastructure deployment into a real pipeline with OIDC.
    How to answer

    The workflow has a build job (restore, build, test, dotnet publish /t:PublishContainer to push an image tagged with the commit SHA to Azure Container Registry) and deploy jobs per environment that reuse that same image.

    For Azure access I use OpenID Connect: the job declares permissions: id-token: write, GitHub issues a short-lived token, and azure/login exchanges it for an Entra token through a federated credential on an app registration or user-assigned managed identity. No client secret is stored anywhere.

    Production is gated with a GitHub environment that has required reviewers, and the federated credential's subject is scoped to environment:production, so only an approved job can get production access.

    The trade-off: OIDC needs one-off Entra setup per repo and environment, but removes secret rotation and leaked-secret risk entirely.

  2. When: Candidate mentions a service principal or secrets in the deployment. Why: Checks how the pipeline identity and any secrets are handled safely.
    How to answer

    My rule is to remove secrets rather than protect them. The pipeline authenticates to Azure with OIDC / workload identity federation: the CI platform issues a short-lived token that Entra trusts, so no client secret is stored. The app authenticates to SQL, Storage and Key Vault with managed identity. Remaining secrets (third-party API keys) live in Key Vault; the pipeline deploys only a Key Vault reference such as @Microsoft.KeyVault(VaultName=...;SecretName=...) as an app setting, and the platform resolves it with the app's identity, so the value never passes through the pipeline.

    Pipeline identities are least privilege: one per environment, roles on a resource group, protected by environment approvals. Secret scanning with push protection blocks committed secrets.

    If a secret leaks, I revoke and rotate first, then clean logs, then check access logs. The trade-off is up-front identity setup in exchange for nothing worth stealing in the pipeline.

  3. When: Candidate lists App Service, SQL or Key Vault as resources in a template. Why: Checks the candidate knows which Azure resources a typical .NET app's template would contain.
    How to answer

    A typical .NET team uses a small, repeatable set of Azure services:

    • Compute: App Service for web apps and APIs, Azure Functions for event-driven code, Container Apps or AKS for containers.
    • Data: Azure SQL Database for relational data, Blob Storage for files, and Azure Managed Redis (the successor to Azure Cache for Redis) for caching.
    • Platform: Key Vault for secrets and certificates, App Configuration for settings and feature flags, Service Bus for messaging, Application Insights (on Azure Monitor) for telemetry.

    Everything is wired together with managed identity and Entra ID RBAC, not connection strings, and deployed with infrastructure as code. The trade-off: managed PaaS services remove patching and plumbing, but you accept each service's limits, pricing model and region availability.

↩ Usually asked after

More in Infrastructure as Code

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me