Review StackSet retention on account removal

Retain required stacks and data when accounts leave a StackSet’s automatic deployment targets.

Description

With automatic deployment enabled, a service-managed StackSet can delete a stack when its account leaves the target organization or organizational unit (OU). RetainStacksOnAccountRemoval controls what happens to that stack.

Potential impact

An account move can interrupt a running service. Recovering deleted resources may require redeploying the stack and restoring data from backups.

Remediation

If the stack must remain, set AutoDeployment.RetainStacksOnAccountRemoval: true before moving the account. Review affected stacks, resource deletion policies and backups. Arrange separate access controls, ownership, cost tracking and cleanup for any stack you retain.

Examples

Both examples require AWS Organizations integration for SERVICE_MANAGED and an accessible S3 template URL in StackTemplateUrl.

Before

yaml
Resources:
  StackSet:
    Type: AWS::CloudFormation::StackSet
    Properties:
      PermissionModel: SERVICE_MANAGED
      StackSetName: some-stack-name
      TemplateURL: !Ref StackTemplateUrl
      AutoDeployment:
        Enabled: true
        RetainStacksOnAccountRemoval: false

After

yaml
Resources:
  StackSet:
    Type: AWS::CloudFormation::StackSet
    Properties:
      PermissionModel: SERVICE_MANAGED
      StackSetName: some-stack-name
      TemplateURL: !Ref StackTemplateUrl
      AutoDeployment:
        Enabled: true
        RetainStacksOnAccountRemoval: true

With false, leaving the deployment target triggers stack deletion. With true, the stack and its resources stay in the account, outside the StackSet’s management.

References