Open blimmer opened 7 months ago
cc @comcalvi who has been working on the CFN changeset diffs lately
Yes you are right. Looks like cdk diff
would not detect the parameter value change but the CFN console would. Making it a p1 and we'll discuss with the team.
Using the example shared by @blimmer, the root cause appears to be that the DifferenceCollection.logicalIds (https://github.com/aws/aws-cdk/blob/main/packages/@aws-cdk/cloudformation-diff/lib/diff/types.ts#L406) doesn't contain all the changed resources. Before hitting this line (406) of code in cdk diff
, we filter for replacements -- and we do find the SqsQueue replacement https://github.com/aws/aws-cdk/blob/main/packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts#L233. So we should make the TemplateDiff.resources contain the changed resource.
Here are the debugger variables at line 233:
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
Just here to 👍🏻 this issue as it is also a problem with EC2 instances where AMIs are often driven by SSM parameters (like new WindowsImage(WindowsVersion.WINDOWS_SERVER_2019_ENGLISH_FULL_BASE)
) which causes a replacement of the EC2 instance despite cdk diff
showing no changes.
https://github.com/aws/aws-cdk/pull/30093 fixed this but was reverted by https://github.com/aws/aws-cdk/pull/30243
Describe the bug
Currently if you use a Systems Manager StringParameter as a value to another resource, the
cdk diff
does not identify a diff when the underlying parameter changes, even when using the new behavior that produces a CloudFormation changeset (vs. template-only diffs). The new behavior to produce a real changeset is designed to identify these types of changes.If I manually create a changeset in the console, it does identify the change, so this feels like an issue specific to the CDK changeset diffing behavior.
Expected Behavior
I expect to be notified that my stack will change, just like I am if I upload the template to the CloudFormation UI. This bug is especially concerning if the change could trigger an unexpected resource replacement (which makes me think this should be a P1 issue).
Current Behavior
cdk diff
saysThere were no differences
when, really, CloudFormation generates a changeset that shows a diff.Reproduction Steps
Consider the following straightforward stack:
It imports an SSM StringParameter and uses the resolved value to name the queue.
blimmer-test-1
.cdk deploy CdkBugReportStack
). You'll see your queue is cre ated with the name of your StringParameter from step 1.blimmer-test-1
toblimmer-test-2
.Run
cdk diff CdkBugReportStack
. Make sure you're using the latest CDK (at time of writing v2.135.0) and that you're generating a changeset for the diff (e.g., not passing--no-change-set
).As you can see, no diffs are identified (even though the underlying parameter did change).
Generate the CloudFormation stack for use in the console in the next steps:
Visit the CloudFormation service page in the AWS Console. Select the stack,
CdkBugReportStack
.Choose "Stack Actions" -> "Create change set for current stack".
npx cdk deploy CdkBugReportStack
and you'll see that the queue is replaced, even though thediff
said no changes were detected.Possible Solution
It feels like if CloudFormation can identify this change, CDK should also be able to identify the change when running the more accurate changeset-based diff.
Additional Information/Context
I was confused why my services were sometimes redeploying when no diffs were shown via
cdk diff
. It turned out that my problem was withobtainDefaultFluentBitECRImage
, which obtains the fluent bit image via an SSM parameter (docs). When the underlying parameter changed, it caused my task definitions and services to be updated.Linking this up with https://github.com/aws/aws-cdk/issues/7366 and https://github.com/aws/aws-cdk/issues/23288, which are related to the specific issue I ran into here.
CDK CLI Version
2.135.0 (build d46c474)
Framework Version
No response
Node.js Version
20 LTS
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response