MigoMindPractical AI & Cloud Skills
All insights

Data Engineering & DevOps

Infrastructure as code: plan changes with confidence

Learn the operating practices behind maintainable infrastructure as code: clear ownership, reusable modules, protected state, reviewed plans, drift handling, and safe environment promotion.

Gajendra RaiUpdated November 7, 20268 minIntermediate

IaC is a change-management practice

Infrastructure as code describes desired resources and relationships in versioned configuration, then uses a provider or platform API to reconcile that intent with real systems. The value is not simply replacing portal clicks: code review, repeatable environments, audit history, automated validation, and planned recovery make infrastructure changes easier to reason about.

Terraform is one common IaC tool, alongside platform templates and other declarative systems. The principles in this guide are broader; verify the exact syntax, state behavior, and provider capabilities for the tool and version you use.

Make ownership and module boundaries explicit

Start with ownership, lifecycle, and blast radius. A root configuration should represent a cohesive unit that a team can plan and change safely. Reusable modules work best when they expose a small, documented interface with safe defaults and versioned releases; a module that forwards every provider option may add indirection without a stable contract.

Separate environments or independently operated systems when they need different access, release cadence, or failure boundaries. Share tested modules and policy rather than coupling every environment to one state file or one large apply operation.

Protect state as a sensitive asset

State connects configuration addresses to real infrastructure objects and may contain sensitive attributes. Keep it out of source control. Use a supported remote backend with access control, encryption, versioning or recovery, and locking when available. Limit who can read or write each environment's state, and audit those permissions.

Marking a value sensitive in configuration does not mean the value is absent from state or saved plans. Avoid putting secrets into IaC where possible, use approved identity and secret-delivery mechanisms, and handle state and plan artifacts according to their sensitivity.

  • Use separate state boundaries aligned to ownership and risk
  • Enable backend locking where supported and do not bypass it casually
  • Keep state backups and test recovery procedures
  • Do not commit state files, credentials, or sensitive saved plans

Review plans as production change proposals

A plan is a proposal, not a guarantee that the remote system will remain unchanged until apply. Validate configuration and provider versions, generate a fresh plan, inspect creations, updates, deletions, replacements, and permission changes, then require the right review for the target environment. Where the tool supports it, apply the same saved plan that was reviewed and protect it as a sensitive artifact.

Run formatting, validation, module tests, security checks, and policy rules in CI. Keep plan and apply identities distinct when practical, and ensure production approvals are enforced by the platform rather than only by a condition written in the same change being reviewed.

Handle drift, imports, and renames intentionally

Drift is a difference between declared intent, recorded state, and the remote object. It may be an emergency fix, a manual mistake, or a change that should become part of configuration. Investigate the reason before reconciling; automatically applying every plan can undo a legitimate incident response.

Renames and adoption of existing resources need explicit state-aware migrations or imports. Before changing state, preserve a recovery point, use the supported tool operation, and inspect a new plan. Never edit a state file by hand simply to make a plan look clean.

Use an environment promotion workflow

A practical flow is: format and validate the change, test modules, plan against a non-production environment, review the resulting resource changes, apply, run smoke checks, then prepare a separately authorized production plan. Promote versioned modules and reviewed configuration rather than copying untracked changes between environments.

For a design exercise, pick one service boundary and document its owner, state location, identity, network boundary, dependencies, deletion behavior, and recovery path. If any of those are unknown, the configuration is not yet an operational design.

Choose your next step

Use the roadmap as a loop, not a reading list. Pick the next action that produces evidence.

Frequently asked questions

Is Terraform state the same as the infrastructure?+

No. State records the relationship between configuration resource addresses and real objects, with metadata and observed attributes. Deleting state does not normally delete the infrastructure, but it can leave the tool unable to manage those existing objects safely.

Should development, staging, and production share one state file?+

Usually not when they have distinct owners, access policies, lifecycles, or blast radii. Separate state boundaries make those differences clearer, while shared versioned modules can still reduce duplication.

What should I do when an IaC plan proposes a destructive replacement?+

Pause and inspect the full plan, provider and module versions, state binding, remote object, and any out-of-band changes. Correct or import deliberately, then review a fresh plan and recovery approach before production apply.

Official sources

Use these primary references to verify product capabilities, exam objectives, and implementation details.

Put this into practice

Use the IaC interview filter to practice safe-plan reviews, state recovery, and module boundaries.

Open resource

Keep building

Related practical guides

Data Engineering & DevOps10 min

Provision Microsoft Foundry with Terraform

Use AzureRM Terraform to create a Microsoft Foundry account and project, secure remote state, authenticate without stored secrets, and review deployments safely.

Intermediate

A decision guide for subscriptions, identity, networking, policy, data boundaries, and observability in an AI platform.

Advanced
Data Engineering & DevOps16 min

Build a GenAIOps pipeline with GitHub Actions

Build a practical GitHub Actions release path for AI applications, evaluation suites, Terraform, and secure Azure deployments using workload identity federation.

Advanced