Skip to content

Commit

Permalink
sam changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
comcalvi committed Feb 22, 2024
1 parent 6f867d6 commit 8c0779b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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);
});

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

0 comments on commit 8c0779b

Please sign in to comment.