Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CLI): sam resources hidden in changeset diffs #29223

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@aws-cdk/cloudformation-diff/lib/diff-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ function addImportInformation(diff: types.TemplateDiff, changeSet: CloudFormatio
function filterFalsePositivies(diff: types.TemplateDiff, changeSet: CloudFormation.DescribeChangeSetOutput) {
const replacements = findResourceReplacements(changeSet);
diff.resources.forEachDifference((logicalId: string, change: types.ResourceDifference) => {
if (change.resourceType.includes('AWS::Serverless')) {
// CFN applies the SAM transform before creating the changeset, so the changeset contains no information about SAM resources
return;
}
change.forEachDifference((type: 'Property' | 'Other', name: string, value: types.Difference<any> | types.PropertyDifference<any>) => {
if (type === 'Property') {
if (!replacements[logicalId]) {
Expand Down
49 changes: 49 additions & 0 deletions packages/@aws-cdk/cloudformation-diff/test/diff-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,55 @@ describe('changeset', () => {
expect(differences.resources.differenceCount).toBe(1);
});

test('SAM Resources are rendered with changeset diffs', () => {
// GIVEN
const currentTemplate = {
Resources: {
ServerlessFunction: {
Type: 'AWS::Serverless::Function',
Properties: {
CodeUri: 's3://bermuda-triangle-1337-bucket/old-handler.zip',
},
},
},
};

// WHEN
const newTemplate = {
Resources: {
ServerlessFunction: {
Type: 'AWS::Serverless::Function',
Properties: {
CodeUri: 's3://bermuda-triangle-1337-bucket/new-handler.zip',
},
},
},
};

let differences = fullDiff(currentTemplate, newTemplate, {
Changes: [
{
Type: 'Resource',
ResourceChange: {
Action: 'Modify',
LogicalResourceId: 'ServerlessFunction',
ResourceType: 'AWS::Lambda::Function', // The SAM transform is applied before the changeset is created, so the changeset has a Lambda resource here!
Replacement: 'False',
Details: [{
Evaluation: 'Direct',
Target: {
Attribute: 'Properties',
Name: 'Code',
RequiresRecreation: 'Never',
},
}],
},
},
],
});
expect(differences.resources.differenceCount).toBe(1);
Comment on lines +1147 to +1167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what would the changes look like before this change?

});

test('imports are respected for new stacks', async () => {
// GIVEN
const currentTemplate = {};
Expand Down
Loading