StackSets, nesting & drift

Multi-account/Region IaC and drift detection.

Advanced30 min · lesson 6 of 15

At professional scale, IaC spans many accounts and Regions and must handle drift. Nested stacks, StackSets, and drift detection are the advanced CloudFormation capabilities that make large estates manageable.

Modularity and multi-account deployment

Nested stacks let you break a large template into reusable child stacks — a networking stack, a database stack, an app stack — composed into a parent, so teams reuse vetted building blocks instead of copying template code. StackSets take this across boundaries: they deploy a stack to many accounts and Regions from a single operation, which is how you roll out a security baseline, a logging configuration, or a standard VPC to an entire organization consistently. Combined with AWS Organizations, StackSets make org-wide, repeatable infrastructure a single managed action rather than a per-account chore.

StackSets deploy across accounts and Regions
# One operation → deploy a baseline stack to every account in an OU, in 3 Regions.
aws cloudformation create-stack-set --stack-set-name org-baseline \
--template-body file://baseline.yaml --permission-model SERVICE_MANAGED
aws cloudformation create-stack-instances --stack-set-name org-baseline \
--deployment-targets OrganizationalUnitIds=ou-xxxx \
--regions eu-west-1 us-east-1 ap-southeast-1
# New accounts moved into the OU can auto-inherit the baseline.

Drift detection and IaC discipline

Even with IaC, someone may change a resource in the console, causing drift — live configuration diverging from the template. CloudFormation drift detection reports these divergences so you can reconcile them (update the template or revert the change), and a DevOps team treats unexplained drift as a signal to investigate. The broader discipline is to make IaC the only path to change: enforce it with preventive guardrails (SCPs, permission boundaries) so out-of-band changes are hard, run IaC scanning (cfn-lint, cfn-nag, Checkov) in the pipeline to catch misconfigurations pre-deploy, and detect drift on a schedule. This is how infrastructure stays consistent, compliant, and reproducible as the estate grows to professional scale.

IaC at professional scale
compose + distribute
nested stacks
reusable building blocks
StackSets
many accounts/Regions, one op
keep it true
drift detection
find out-of-band changes
IaC-only + scanning
guardrails + pre-deploy checks
Nested stacks for reuse, StackSets for org-wide rollout, drift detection + IaC-only workflows to keep live state matching code.
Out-of-band changes silently break reproducibility
If people change infrastructure in the console instead of through IaC, your templates no longer describe reality and the next deployment may revert or conflict with the change. Make IaC the only sanctioned path with preventive guardrails, run scheduled drift detection, and treat unexplained drift as an incident to reconcile.