[cdk diff] Modifications to stack-level tags do not surface in cdk diff results, leading to unexpected updates
- Dominant language
- TypeScript
- Stars
- 105
- Forks
- 122
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 71
Description
### Describe the bug
When you make a change to a stack-level tag in CDK, `cdk diff` returns `There were no differences` even though changes to stack-level tags do in fact results in updates to resources. This results in inaccurate diff results that can lead to unexpected updates.
In comparison - When you make a change to a stack-level tag and then create a CloudFormation ChangeSet, CloudFormation **does** report this as a change. It lists a `Modify` operation for all supported resources.
The `cdk diff` command creates (and then immediately deletes) a CloudFormation ChangeSet, and this ChangeSet does accurately report the `Modify` behavior, but the actual `cdk diff` results in the CDK CLI still returns `no differences` despite this. I have provided screenshots of this below.
**CloudFormation ChangeSet:**
**CDK Diff Results**:
In other words, this doesn't appear to be an issue or limitation with the CloudFormation ChangeSet behavior. This specifically looks like a limitation with how CDK diff parses and returns ChangeSet results when stack-level tags are involved.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Version
_No response_
### Expected Behavior
CDK diff should accurately report changes to resources when changes are made to stack-level tags.
### Current Behavior
CDK diff incorrectly returns "There were no differences" despite the CloudFormation ChangeSet reporting differences.
### Reproduction Steps
1. Create a CDK stack. As an example, I made one that just creates an SNS topic:
```
import * as cdk from 'aws-cdk-lib/core';
import * as sqs from 'aws-cdk-lib/aws-sqs';
import { Construct } from 'constructs';
export class CdkDiffReplicationStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new sqs.Queue(this, 'Queue');
}
}
```
2. Define one or more stack tags. For example:
```
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib/core';
import { CdkDiffReplicationStack } from '../lib/cdk_diff_replication-stack';
const app = new cdk.App();
new CdkDiffReplicationStack(app, 'CdkDiffReplicationStack', {
// Specialize for the account/region from the current CLI configuration.
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
},
// stack-level tag
tags: {
DiffReplicationTag: 'Original',
},
});
```
3. Deploy the stack
4. Make a change to the stack-level tag in the CDK code:
```
tags: {
DiffReplicationTag: 'Changed', //<---Changed the value
},
```
5. Run CDK diff - Observe that the command returns `There were no differences`.
6. In the CloudFormation console, manually create a CloudFormation ChangeSet. Use the same template but change the value of the stack-level tag. Observe that CloudFormation does report changes for these resources.
### Possible Solution
_No response_
### Additional Information/Context
_No response_
### CDK CLI Version
2.1141.0
### Framework Version
_No response_
### Node.js Version
v24.14.0
### OS
Windows 10
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start by reproducing the issue with the example in lib/cdk_diff_replication-stack and the stack-level tags shown in the app entry point, then run cdk diff and compare its output with a CloudFormation ChangeSet. Trace how the CLI parses ChangeSet results; done means cdk diff reports the resource modifications caused by changing the tag value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cli, cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100