What it is
Infrastructure as code (IaC) describes cloud resources such as networks, servers, databases, permissions and DNS records in text files that live in version control. A tool compares that description with what actually exists and makes the changes needed to match. The result is infrastructure that is documented, reviewable and reproducible.
When you need it
- Environments are built by hand and nobody is sure how production differs from staging.
- Rebuilding an environment after a mistake would take days.
- Infrastructure changes happen without review or record.
- Several teams need consistent, secure building blocks.
How we approach it
State comes first. Most declarative tools keep a state file that maps code to real resources. We store it remotely with locking, encryption and versioning, and split it by environment and component so a single change has a limited blast radius.
We build modules: reusable, versioned building blocks such as a network, a database or a service deployment, with secure defaults baked in. Teams compose environments from these modules instead of copying code, so improvements reach everyone through a version update.
Changes follow a plan and apply workflow. A pull request triggers a plan that shows exactly what will be created, changed or destroyed. A reviewer reads the plan, not only the code, before approving. The pipeline then applies the change with its own short-lived credentials, so people do not need write access to production.
Policy as code checks run on every plan to block resources that break your standards, such as public storage or missing encryption. Drift detection runs on a schedule and reports any manual changes, so the code stays the source of truth.
For existing environments, we import resources step by step until everything is managed.
Common pitfalls to avoid
- Local state files. State on a laptop gets lost or overwritten. Use remote, locked storage.
- One giant state. A single state for everything makes plans slow and mistakes far-reaching.
- Approving code without reading the plan. A small code change can trigger a resource replacement that deletes data.
- Secrets in code or state. Pull secrets from a secrets manager and protect state, which may contain sensitive values.
- Unpinned module versions. Pin versions so an upstream change does not alter production unexpectedly.