Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

bug: CloudFormation v2 engine fails to delete stack with conditional resource references #13609

@sodre

Description

@sodre

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When deleting a CloudFormation stack that contains conditional resources (Condition: attribute) where the condition evaluated to false during creation, the v2 engine fails with:

Template format error: Unresolved resource dependencies [MyQueue] in the Resources block of the template

The stack was created successfully, but deletion fails even though the referenced resource (MyQueue) was never created.

Expected Behavior

Stack should delete successfully since the conditional resource was never created. The legacy engine (PROVIDER_OVERRIDE_CLOUDFORMATION=engine-legacy) handles this correctly.

How are you starting LocalStack?

With a docker run command

Steps To Reproduce

  1. Start LocalStack (v2 engine - default):
docker run -d -p 4566:4566 \
  -e SERVICES=cloudformation,sqs \
  localstack/localstack
  1. Save this template as template.yaml:
AWSTemplateFormatVersion: '2010-09-09'
Description: Minimal reproduction of CloudFormation v2 deletion bug

Parameters:
  DeployQueue:
    Type: String
    Default: 'true'
    AllowedValues:
      - 'true'
      - 'false'

Conditions:
  ShouldDeployQueue: !Equals [!Ref DeployQueue, 'true']

Resources:
  # This resource is conditionally created
  MyQueue:
    Type: AWS::SQS::Queue
    Condition: ShouldDeployQueue
    Properties:
      QueueName: conditional-queue

  # This resource always exists but references the conditional resource
  AlwaysCreatedResource:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: always-created-queue
      Tags:
        - Key: ConditionalQueueArn
          Value: !If
            - ShouldDeployQueue
            - !GetAtt MyQueue.Arn
            - "not-deployed"

Outputs:
  AlwaysCreatedQueueUrl:
    Value: !Ref AlwaysCreatedResource
  1. Create the stack with DeployQueue=false (so MyQueue is NOT created):
awslocal cloudformation create-stack \
  --stack-name repro-bug \
  --template-body file://template.yaml \
  --parameters ParameterKey=DeployQueue,ParameterValue=false

awslocal cloudformation wait stack-create-complete --stack-name repro-bug
  1. Delete the stack:
awslocal cloudformation delete-stack --stack-name repro-bug

Result: Deletion fails with "Unresolved resource dependencies [MyQueue]"

Environment

  • OS: macOS / Linux
  • LocalStack version: 4.12.1

Anything else?

The v2 engine incorrectly resolves !GetAtt MyQueue.Arn during deletion even when MyQueue was never created (because ShouldDeployQueue condition was false).

Workaround: Use PROVIDER_OVERRIDE_CLOUDFORMATION=engine-legacy

Related: zeroae/zae-limiter#85

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions