2.2 - Infrastructure as Code (IaC)
Cloud+ CV0-004 objective 2.2 covers Infrastructure as Code (IaC), defining infrastructure in declarative template files for repeatable, versioned builds. A declarative blueprint states the desired end state and the tool figures out how to reach it, unlike an imperative script that lists each step. You package reusable IaC into a parameterized unit that other blueprints can call, which is a module. IaC also shapes how you manage servers: mutable infrastructure edits and patches live servers over time, while immutable infrastructure replaces servers with new images instead of changing them, avoiding drift. You should also know state files, idempotency, and tools like Terraform and CloudFormation. Expect scenario questions that describe defining infrastructure in code, declaring desired state, reusing a parameterized template, or patching versus replacing servers, and ask which IaC concept - declarative, module, mutable or immutable - applies.
Infra defined in versioned template files = IaC. States desired end state, tool works out how = declarative. Reusable parameterized IaC unit = module. Patch live servers = mutable; replace with new images = immutable.
Practice questions
1. Defining infrastructure in declarative template files for repeatable, versioned builds is called:
- Automatic scaling
- Infrastructure as Code (correct answer)
- Network load balancing
- Volume snapshotting
Infrastructure as Code (IaC) provisions resources from version-controlled templates (Terraform, CloudFormation), making builds repeatable and auditable.
2. Rather than patch a running server, your team rebuilds it from an image on every change. This approach is:
- Immutable infrastructure (correct answer)
- Mutable infrastructure
- Manual configuration
- In-place patching
Immutable infrastructure never modifies a live server; each change produces a fresh image that replaces the old instance. This removes drift and eases rollback.
3. A blueprint provisions a database before the app that reads from it. What must the tool respect to succeed?
- Region affinity
- Dependency ordering (correct answer)
- Session stickiness
- Cost tagging
Dependency ordering ensures resources build in the right sequence: the database exists before the app that references it. IaC tools infer this from a dependency graph.
4. An imperative provisioning script differs from a declarative one because it:
- Lists the exact steps to run (correct answer)
- States only the end goal
- Cannot be stored in Git
- Never uses variables
Imperative code specifies each step in order to reach a state; declarative code specifies the desired end state and lets the tool figure out the steps. Both can live in Git.
5. Bringing your existing software license to run on cloud instances instead of renting one is:
- Pay-as-you-go
- BYOL (correct answer)
- Open source
- Metered use
BYOL (Bring Your Own License) lets you reuse licenses you already own on cloud instances, often cutting cost. Pay-as-you-go bundles the license into the hourly rate.
6. A key benefit of storing IaC templates in version control is that you can:
- Skip all automated testing
- Review and roll back changes (correct answer)
- Avoid writing any documentation
- Bypass all access control checks
Versioned IaC gives peer review, history and rollback of infrastructure changes, treating infrastructure like application code. It does not remove the need for testing or access control.