IICTPIICTP

Blog / Guides

Answers1 November 20265 min read

What is infrastructure as code, and why use it?

Infrastructure as code (IaC) means describing servers, networks and cloud services in files that a tool applies, instead of building them by hand in a console. The files are versioned and reviewed like application code, so the environment can be recreated, compared and changed safely.

In this post
  1. What is the difference between declarative and imperative IaC?
  2. What are the main benefits?
  3. What is drift, and how do you handle it?
  4. How should state and secrets be handled?
  5. What is a safe change process?
  6. Where do you start?
  7. Sources and further reading

What is the difference between declarative and imperative IaC?

A declarative definition states the end result you want, and the tool works out the steps. An imperative script lists the steps to run. Most modern tools are declarative, because re-running them is safe: they change only what differs from the desired state.

What are the main benefits?

Environments become repeatable, so staging can match production. Every change is recorded in version control, reviewed before it is applied, and can be rolled back. It also shortens recovery, because a lost environment can be rebuilt from the files.

What is drift, and how do you handle it?

Drift is the gap that opens when someone changes a resource by hand and the files no longer describe reality. Detect it by comparing the real state with the code on a schedule, and then either bring the code up to date or put the resource back. Restricting console access reduces it.

How should state and secrets be handled?

Many tools keep a state file recording what they created. Store it in a shared, access-controlled location with locking, since it may contain sensitive values. Keep secrets in a secret manager and reference them, rather than writing them into the files.

What is a safe change process?

Run a plan or preview that shows what will change, have a person review it, apply it from a pipeline rather than a laptop, and add policy checks that block risky changes such as public storage. Small, frequent changes are easier to review than large ones.

Where do you start?

Pick one non-critical environment and define it in code, then expand. Begin by importing existing resources rather than rebuilding them, and agree naming and module conventions early so teams do not diverge.

Sources and further reading

  1. HashiCorp. Terraform documentation. developer.hashicorp.com/terraform.
  2. Morris, K. Infrastructure as Code. O’Reilly, 2nd ed. 2020.

IICTP is an independent technical credentialing body.

Keep reading

← All posts

Where do you stand?

Find the credential that fits the work you do.