Review StackSet stack retention

Decide whether to retain the stack when removing a StackSet instance.

Description

When Terraform removes an aws_cloudformation_stack_set_instance, retain_stack determines whether the underlying CloudFormation stack stays in its account.

Potential impact

Deleting a production stack can interrupt services or remove data. A retained stack and its resources need an owner outside the StackSet.

Remediation

To keep the stack, set retain_stack = true and run a separate apply. Confirm the value is in Terraform state before applying the change that removes the instance. Assign responsibility for the retained stack and its eventual cleanup.

Examples

Both examples target the same account, Region and StackSet. Substitute the account and Region for your deployment.

Before

hcl
resource "aws_cloudformation_stack_set_instance" "example" {
  account_id     = "123456789012"
  region         = "us-east-1"
  stack_set_name = aws_cloudformation_stack_set.example.name
  retain_stack   = false
}

After

hcl
resource "aws_cloudformation_stack_set_instance" "example" {
  account_id     = "123456789012"
  region         = "us-east-1"
  stack_set_name = aws_cloudformation_stack_set.example.name
  retain_stack   = true
}

References