Skip to main content
PacketMentor logo
← All topics
Automation & Programmability Foundational

Infrastructure as Code (IaC) Principles

What IaC actually means for a network team: write the desired state in files, store in Git, let a tool make it so. Idempotency, declarative vs imperative, version control, review workflow.

Quick summary
  • IaC = the state of your infrastructure described in text files you commit to Git, applied by a tool (Ansible, Terraform, Cisco NSO).
  • Declarative = describe the end state; tool figures out the diff. Imperative = write the steps. Declarative is the modern default.
  • Idempotent = running the same code N times leaves the system in the same final state as running it once. Core property of good IaC.

Studying for an exam? Get a free study plan from a Cisco NetAcad instructor. 20 minutes, no card.

Mental model

Cisco objective 5.5 says “Describe the principles of infrastructure as code”.

Infrastructure as Code = the desired state of your infrastructure (servers, VLANs, firewall rules, DNS entries) lives in text files in a Git repository. A tool reads those files and reconciles the live infrastructure to match.

Instead of:

  • Admin SSHes to router, types config, saves, hopes it is right.

You get:

  • Developer commits a change to the configs repo.
  • Pipeline runs lint and dry-run.
  • Reviewer approves.
  • Pipeline pushes to prod. Diff of before/after is in Git history forever.

Five principles

1. Declarative

Describe what you want, not how to get there. The tool figures out the diff.

Declarative (Terraform, CiscoDevNet iosxe provider):

resource "iosxe_vlan" "data" {
  vlan_id = 10
  name    = "data"
}

Imperative (bash):

ssh switch "configure terminal; vlan 10; name data; end; wr mem"

Declarative wins because it handles both “create this VLAN” and “ensure this VLAN exists” with the same code. If the VLAN already exists, Terraform notices and does nothing.

2. Idempotent

Running the same code N times leaves the system in the same final state as running it once. No side effects on repeat runs.

Why it matters: pipelines re-run, scripts resume after failures, humans mash the Run button twice. Non-idempotent code creates duplicate VLANs or crashes on the second run.

3. Version controlled

Every change goes through Git. You get:

  • History — who changed what, when, why.
  • Review — PR / MR workflow before anything hits prod.
  • Rollback — git revert and re-apply.
  • Diff — see the exact lines that changed.

4. Automated application

A pipeline (CI/CD) applies the change, not a human running commands. Removes the “late Friday night SSH” risk and ensures the same process every time.

5. Immutable preferred

Prefer replacing an entire resource over mutating it in place. On servers: build a new image, launch new instances, retire old. On network: replace a config, do not patch.

Not always possible (physical switches cannot be “replaced”) but the mindset catches drift.

Tools in the IaC space

Tool Shape Where it shines
Ansible Imperative-ish declarative (tasks that are idempotent); SSH or API Config of servers and network devices; agentless
Terraform Fully declarative; providers for AWS/Azure/GCP/Cisco/etc. Cloud resources, provider-rich ecosystem
Cisco NSO Declarative, model-driven; speaks NETCONF/RESTCONF natively Cross-vendor network service orchestration
Pulumi Declarative, using real programming languages (Python/TS/Go) Teams that prefer code over DSL
CloudFormation / ARM AWS- / Azure-native declarative Vendor-locked but tight integration

Lifecycle

Developer writes/updates .tf or .yml file
          │
          ▼
      git commit + push
          │
          ▼
      CI pipeline runs:
        - lint (yamllint, terraform fmt, ansible-lint)
        - dry run (terraform plan, ansible-playbook --check)
          │
          ▼
      Human review on the PR
          │
          ▼
      CD pipeline applies (terraform apply, ansible-playbook)
          │
          ▼
      State recorded (terraform state, Ansible facts)
          │
          ▼
      Monitor + alert on drift

Common anti-patterns

  • Config in Git but changes still made manually (“drift”).
  • Secrets committed in plaintext.
  • No PR review (“I will just push, it is small”).
  • Everyone has prod access; no CI gating.
  • No terraform plan before apply.

FAQ

Is Ansible IaC? Yes. Ansible is slightly imperative-flavoured (tasks run top to bottom) but each task is required to be idempotent, which gives most IaC benefits.

Is bash scripts IaC? Technically yes if stored in Git and idempotent. In practice bash scripts tend to drift from idempotent fast; prefer a real IaC tool.

What is GitOps? IaC + “Git is the sole source of truth”. A controller (ArgoCD, Flux) continuously reconciles live state to Git. See DevOps principles.

Do I need to pick one tool? Many teams use Terraform for cloud infrastructure and Ansible for inside-the-server config. They complement rather than compete.

Master this on a real network

Want this drilled into reflex?

1:1 weekly sessions, live feedback on your labs, and US interview prep: built around the CCNA Automation® exam blueprint. Free first session. No card on file until you decide.

Claim my free session →
Free first session

Stuck on Infrastructure as Code (IaC) Principles?

Walk your plan with a Cisco NetAcad instructor in a free 20 minute call. We find the one thing blocking you and name the next step. No card. No pitch.

  • 20 minutes, 1:1 with a Cisco NetAcad instructor
  • No card, no obligation, no sales pitch
  • You pick the slot that fits your week
Book free session
Free first session

Get your study plan in a free 20-minute call

  • ✓ 1:1 with a senior network engineer, by video
  • ✓ You leave with a written study plan and a realistic exam date
  • ✓ No card, no sign-up, no sales pitch