Skip to content

core: CDK breaks when CFN template is updated outside of CDK #1911

Description

@nonspecialist

Describe the bug

This one was a surprise and only came about because of a mistake. This issue has been replicated with CDK 2.1138.0 (build a4c0282).

An existing CFN stack (created by CDK) with a resource with a DeletionPolicy can be updated outside of CDK in a way that breaks all future CDK runs against that stack, while being perfectly acceptable to CloudFormation.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

CDK should not break on existing templates that CloudFormation is quite happy with

Current Behavior

A manual update to a stack can cause CDK to fail in unexpected ways; diagnosing the problem via the console or AWS CLI does NOT reveal the problem.

Reproduction Steps

  1. Start with an existing CDK app created without modification using the CDK "getting started" example (mkdir hello-world && cd hello-world && cdk init sample-app --language=typescript) and deployed
  2. Copy the JSON template (either from the CloudFormation console, or from aws cloudformation get-template ...) and, in the resource definition for the AWS::SQS::Queue, make the following change:

FROM

    "CdkShouldFailQueueF196B131": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "VisibilityTimeout": 300
      },
      "UpdateReplacePolicy": "Delete",
      "DeletionPolicy": "Delete",
      "Metadata": {
        "aws:cdk:path": "CdkShouldFailStack/CdkShouldFailQueue/Resource"
      }
    },

TO

    "CdkShouldFailQueueF196B131": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "VisibilityTimeout": 300
      },
      "UpdateReplacePolicy": "Delete",
      "DeletionPolicy": "Delete",
      "UpdateReplacePolicy": "Retain",
      "DeletionPolicy": "RetainExceptOnCreate",
      "Metadata": {
        "aws:cdk:path": "CdkShouldFailStack/CdkShouldFailQueue/Resource"
      }
    },

A second UpdateReplacePolicy and DeletionPolicy key has been added.
3. Update the stack in place (either via changeset or directly), using the console or command line but NOT using CDK
4. Now do cdk diff and see the failure Map keys must be unique; "UpdateReplacePolicy" is repeated

Possible Solution

No response

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

aws-cdk-lib@2.266.0

AWS CDK CLI version

2.1138.0 (build a4c0282)

Node.js Version

Node.js v22.22.2

OS

Linux (Fedora 43)

Language

TypeScript

Language Version

No response

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions