Infrastructure as Code

Infrastructure as code provisions and manages infrastructure through version-controlled definitions; declarative tools like Terraform converge the real environment to a desired state idempotently, tracking reality in a state file.

Key formulas & points

Skim these first — then read the full notes below.

  • Declarative (Terraform, CloudFormation) versus imperative approaches
  • Modules make infrastructure patterns reusable
  • Drift detection flags manual out-of-band changes

Topic details

Introduction

This topic covers automating infrastructure. You write declarative definitions, understand the plan/apply workflow and idempotency, manage state and detect drift, and reuse patterns through modules for consistent, repeatable environments.

Key relations & formulas

Formulas (Indian textbook notation)

  • Terraformworkflow:plan(preview)apply(convergetodesiredstate)Terraform workflow: plan (preview) → apply (converge to desired state)

Formulas (Indian textbook notation)

  • idempotent:applyingthesameconfigyieldsthesameinfrastructureidempotent: applying the same config yields the same infrastructure

Formulas (Indian textbook notation)

  • astatefilemapsconfigurationtorealresourcesa state file maps configuration to real resources

Notation and sign conventions

Relation 1 —
Terraformworkflow:planTerraform workflow: plan

Formulas (Indian textbook notation)

  • Terraformworkflow:plan(preview)apply(convergetodesiredstate)Terraform workflow: plan (preview) → apply (converge to desired state)
Write this relation with symbols exactly as in Gene Kim Devops Handbook — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 2 —
idempotent:applyingthesameconfigyieldsthesameinfrastructureidempotent: applying the same config yields the same infrastructure

Formulas (Indian textbook notation)

  • idempotent:applyingthesameconfigyieldsthesameinfrastructureidempotent: applying the same config yields the same infrastructure
Write this relation with symbols exactly as in Gene Kim Devops Handbook — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 3 —
astatefilemapsconfigurationtorealresourcesa state file maps configuration to real resources

Formulas (Indian textbook notation)

  • astatefilemapsconfigurationtorealresourcesa state file maps configuration to real resources
Write this relation with symbols exactly as in Gene Kim Devops Handbook — Standard reference before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.

Concept in depth

Infrastructure as code applies software-engineering discipline to servers and networks: definitions live in version control, are reviewed, and are applied automatically, so environments become reproducible instead of hand-crafted snowflakes. Declarative tools let you state the desired end state and figure out the steps to reach it, and because operations are idempotent, re-applying the same configuration makes no changes if reality already matches. A state file records the mapping between configuration and actual resources so the tool knows what it manages and can compute the minimal changes on the next apply. Drift — someone changing infrastructure manually — is detectable by comparing state to reality, restoring the guarantee that the code is the source of truth.

Assumptions and validity limits

State assumptions explicitly before using any relation for infrastructure as code — steady state, uniform properties, linear elastic material, ideal gas, incompressible flow, etc., as applicable.
Wrong assumptions invalidate the entire solution even when the formula is correct. In DevOps viva and GATE descriptive questions, listing valid assumptions often earns separate marks.

Step-by-step problem approach

1. Read the question and list given data with SI units (common in DevOps papers).
2. Draw a neat labelled diagram where applicable — examiners in Indian universities award diagram marks even when arithmetic slips.
3. Identify which relation from this topic applies to infrastructure as code.
4. Use equation 1:
Terraformworkflow:planTerraform workflow: plan
.
5. Use equation 2:
idempotent:applyingthesameconfigyieldsthesameinfrastructureidempotent: applying the same config yields the same infrastructure
.
6. Substitute values, compute, and verify units and sign (direction).
7. State conclusion in one line — e.g. safe/unsafe, stable/unstable, feasible/infeasible.

Applications & exam relevance

Infrastructure as Code appears in modern software delivery. In Indian it software curricula this topic is tested because it connects theory to CI/CD and infrastructure as code.
GATE and semester exams often combine infrastructure as code with earlier units — revise prerequisites before attempting mixed problems.
Industry interview panels sometimes ask: "Where did you use infrastructure as code?" — answer with a lab, mini-project, or plant visit example if possible.

Common mistakes in exams

Students edit infrastructure manually and cause drift from the code, misunderstand idempotency (expecting re-apply to duplicate resources), and mishandle or fail to secure the state file. Confusing declarative (state the goal) with imperative (state the steps) approaches is common.

Quick revision checklist

Before attempting infrastructure as code problems, confirm you can:
1. Declarative (Terraform, CloudFormation) versus imperative approaches
2. Modules make infrastructure patterns reusable
3. Drift detection flags manual out-of-band changes
Revise the solved examples in Gene Kim Devops Handbook — Standard reference and one previous-year GATE or university paper for this unit.

Worked examples

Try the problem first — open the solution when you are ready to check.

Idempotency of apply

Problem

A Terraform config for 3 servers is applied, then applied again with no changes. What happens on the second apply?

Solution

Nothing changes: because operations are idempotent and the state already matches the desired config, the plan shows no actions. Re-applying does not create additional servers.

Conceptual check — Infrastructure as Code

Problem

In a DevOps semester or GATE paper you are asked: "State the main assumption, the governing relation, and one practical consequence of infrastructure as code." What should a complete answer include?

📖 Standard books (India)

  • Gene Kim Devops HandbookStandard reference

    Read: Syllabus unit

    Referenced in Indian B.Tech syllabus