Skip to content

(core): refactor failed with (seemingly) identical resources #35718

@sdasgupta-spectra

Description

@sdasgupta-spectra

Describe the bug

Firstly, I'd like to say thanks so much for implementing this feature! It's timely and should be super useful. I am attempting to perform a refactor, but stuck on one state machine that cdk refactor is unable to reconcile as unchanged between stacks. I had initially been having the same issues on another state machine, but realized that some of the unicode characters hadn't translated properly to the CloudFormation template and was able to get refactor working there.

This state machine has no diff between the local template and what's on CloudFormation except for the following log groups at the end (also being refactored), but I'm confused why this would have worked on the other state machine that had almost the same log group definitions.

       {
        "CloudWatchLogsLogGroup": {
         "LogGroupArn": {
-         "Fn::GetAtt": [
-          "betapipelinedefinitionloggroup<...>",
-          "Arn"
-         ]
+         "Fn::ImportValue": "cw-stack:ExportsOutputFnGetAttdalgostatemachineloggroup<...>"
         }
        }
       }
@@ -720,7 +717,7 @@
      "Level": "ERROR"
     },
     "RoleArn": {
-     "Fn::ImportValue": "shared-resources-stack:ExportsOutputFnGetAttalgostatemachinerole<...>"
+     "Fn::ImportValue": "iam-stack:ExportsOutputFnGetAttalgostatemachinerole<...>"
     },
     "StateMachineName": "beta-pipeline-definition",
     "StateMachineType": "STANDARD",
@@ -732,15 +729,6 @@
     ]
    },
    "Metadata": {
-    "aws:cdk:path": "beta-pipeline-stack/beta-pipeline-definition"
+    "aws:cdk:path": "statemachine-stack/beta-pipeline-definition"
    }
   },

Any assistance here would be appreciated or debugging steps that might elucidate why the stacks are showing as not the same.

The exact error I'm seeing is listed below.

Running a verbose output with this didn't seem to give more information about why the stacks don't match. I am including the statemachine-stack as an additional stack with --additional-stack-name=<STACK> and the other resources in that stack are not causing a problem.

Regression Issue

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

Last Known Working CDK Library Version

No response

Expected Behavior

Clean refactor with the cdk refactor recognizing that beta-pipeline-definition is the same between the old and new stack.

Current Behavior

Refactor failed: A refactor operation cannot add, remove or update resources. Only resource moves and renames are allowed.
The following resources are present only in the AWS environment:
  - statemachine-stack/beta-pipeline-definition

The following resources are present only in your CDK application:
  - beta-pipeline-stack/beta-pipeline-definition

Reproduction Steps

cdk refactor --unstable=refactor -c env=dev --dry-run --additional-stack-name=statemachine-stack <all-stacks-to-include>

Possible Solution

I tried comparing the CloudFormation template for the old resource with the new one that is generated in cdk.out using a git diff. Looking for a way to confirm difference/similarities between these two or understand better how the cdk refactor command determines whether or not there is a difference.

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.219.0

AWS CDK CLI version

2.1029.4 (build 09c0061)

Node.js Version

v22.17.0

OS

MacOS 15.6.1 (24G90)

Language

TypeScript

Language Version

^5.9.3

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/mediumMedium work item – several days of effortinvestigatingThis issue is being investigated and/or work is in progress to resolve the issue.p2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions