
What's the deal with AWS CloudFormation StackSets?
A deep-dive into a powerful infrastructure provisioning service: Learnings, pitfalls and guidelines
⚠️ The official documentation can be confusing and lacking
⚠️ Limited support for parameter overrides for service-managed stack sets
⚠️ Issues with automatic deployment and account level targeting for service-managed stack sets
⚠️ Parameter overrides don't apply to auto-deployed stacks for service-managed stack sets
⚠️ Parallelism not respected when using different parameter override values
<account-name>.example.com
).
- Automatic deployment: When enabled, StackSets will automatically deploy stacks to new accounts as they're added to the targeted OUs, and remove stacks when accounts leave those OUs. This sounds incredibly convenient—imagine having all your governance and security baselines automatically applied to every new account! However, as we'll explore later, this convenience comes with some surprising behaviors.
- Account level targeting: This feature provides more granular control over which accounts are targeted by your stack set. You can use an INTERSECTION filter type to deploy only to specific accounts within an OU, DIFFERENCE to exclude certain accounts, or UNION to deploy to an OU and one or more accounts residing in different OUs. This flexibility is powerful, but as we'll see, it introduces some unexpected behaviors.
template.yml
and use the following CLI command (replacing <ou-id>
and <account-id>
):- Lean towards self-managed stack sets: while the self-managed model can be a bit more work because you need to manually maintain a list of target accounts for your stack set and trigger an update to apply any changes, it has less surprising behavior and is more flexible. If you need to deploy across AWS organizations, want to have granular control over which accounts are deployed to, or you think you'll need account-specific parameter values in your stacks, you probably want to go with the self-managed model!
- Understand the potential pitfalls of using service-managed stack sets: This is especially important with automatic deployment enabled. You should understand the distinction between stack instances deployed through a stack set update versus those that have been auto-deployed (e.g., when a new account has been added to an OU). They behave differently and have different lifecycle rules, especially when coupled with account level targeting. One of the main benefits from the service-managed model is automatic deployment, but if you're not using that, you might want to go with the self-managed model.
- Consider a hybrid approach: you can use a service-managed stack set to automatically set up an IAM execution role in all accounts, then use that role for all your self-managed stack sets. This appears to be the approach used by AWS Control Tower, as an example.
- Have a testing environment for critical stack sets: if your stack set will deploy fairly critical resources, strongly consider having a separate version of the stack set for testing purposes (e.g., in a staging environment) that you can test new changes against.
- Maintain your stack sets using Infrastructure as Code (IaC): create and update your stack set using IaC, and set up a deployment pipeline for it. In my experience the StackSets support in CloudFormation (and the AWS CDK) seems more mature than in the Terraform AWS provider (and the Terraform AWS Cloud Control provider).
- Learn the basics using self-managed stack sets: if you're new to StackSets, consider starting with a self-managed stack set in a sandbox account. This approach doesn't require management account access or delegated administrator privileges, allows for isolated testing, and gives you hands-on experience.