Instiq
Chapter 2 · Configuration Management and IaC·v2.1.0·Updated 6/28/2026·~11 min

What's changed: In-scope coverage: added Control Tower, Service Catalog, AWS Proton to s2; OpsWorks, License Manager, EC2 Image Builder to s3

2.1CloudFormation and IaC Fundamentals

Key points

Understand infrastructure as code—CloudFormation (templates/stacks), change sets, drift detection, and nested stacks. Manage infrastructure declaratively and reproducibly.

Infrastructure as Code (IaC) declares infrastructure in code for reproducible provisioning. On AWS, CloudFormation is the core.

2.1.1How CloudFormation works

Diagram of how CloudFormation works: from a template (declaring resources in YAML/JSON) you create/update a stack; before updates, a change set previews the diff to be applied; drift detection checks whether actual configuration has diverged from the template; common parts are reused via nested stacks; and failed creates auto-roll back—declarative provisioning end to end.
CloudFormation declarative provisioning
  • Template/stack: declare resources in YAML/JSON and create/update/delete them together as a stack.
  • Change set: preview an update before applying to avoid unintended replacements/deletions.
  • Drift detection: detect whether the actual configuration has diverged from the template.
  • Nested stacks: modularize and reuse common templates to organize large stacks.
Exam point

Common on DOP-C02: preview diff before apply = change set, detect manual-change drift = drift detection, reuse common parts = nested stacks, auto-rollback on failure. In production, review via change sets before executing.

Note

CDK and SAM ultimately synthesize CloudFormation templates. CDK lets you write IaC in programming languages; SAM offers concise serverless syntax.

DOP-C02 probes the design skill to wield template features. Externalize environment differences with Parameters, branch by region/environment with Mappings/Conditions, and loosely couple stacks via Outputs with exports/Fn::ImportValue or SSM parameter (dynamic) references. To prevent update accidents, forbid replacement of critical resources (e.g., DBs) with a stack policy, prevent accidental deletion per-resource with DeletionPolicy: Retain/Snapshot, and preserve data on replacement with UpdateReplacePolicy. If an update fails midway, CloudFormation auto-rolls back to the prior state; an UPDATE_ROLLBACK_FAILED state requires manual recovery (continue update rollback). Custom resources (Lambda-backed) and macros embed non-standard processing, and third-party resource types in the Registry are supported. Drift detection surfaces "manual changes made outside the template," making it operationally central to IaC consistency. In production, always follow the change-set review → execute sequence.

GoalFeatureKey point
Preview update diffChange setSee replacements/deletions before apply
Detect manual driftDrift detectionDiff between live config and template
Protect critical resourcesStack policy / DeletionPolicyForbid replace; prevent deletion (Retain/Snapshot)
Organize large stacksNested stacksModularize/reuse common templates
Note

Scenario: On a production stack update, prevent the RDS DB instance from being accidentally replaced (recreated, losing data). → First check the change set for any resource showing "Replacement: True." Set DeletionPolicy: Snapshot and UpdateReplacePolicy: Snapshot on the DB, and use a stack policy to deny updates (replacement) of the DB resource—technically blocking an accidental replace.

Note

FAQ: How to share values between stacks? Two ways. Output exports + Fn::ImportValue create a strong dependency (you can’t delete/change an exporter while imported) but are explicit. SSM parameter (dynamic) references are loosely coupled and easier to repoint later. Choose by whether you want tight or loose coupling.

Warning

Exam trap: When you want to "bring manual console changes into CloudFormation," drift detection only detects the diff—it does not auto-fix. Remediate by updating the template or using resource import. Also, a change set is a "pre-apply preview"; nothing changes unless you execute it.

2.1.2Section summary

  • IaC = CloudFormation (template/stack)
  • Safe ops = change sets + drift detection + nested stacks

Sign in to track progress — Log in.

Quick check

(just a quick review)

Q1. You want to preview a CloudFormation stack update (including replacements/deletions) before applying. What?

Q2. Someone made manual console changes; you want to check if the live environment diverges from the template. What?

Q3. You want to modularize and reuse a common network definition across stacks. What?

Check your understandingPractice questions for Chapter 2: Configuration Management and IaC