diff --git a/packages/@aws-cdk/integ-runner/lib/runner/snapshot-test-runner.ts b/packages/@aws-cdk/integ-runner/lib/runner/snapshot-test-runner.ts index c832d1a3f5437..7d42ee8e8f712 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/snapshot-test-runner.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/snapshot-test-runner.ts @@ -198,13 +198,16 @@ export class IntegSnapshotRunner extends IntegRunner { }); continue; } else { + const config = { + diffAssets: this.actualTestSuite.getOptionsForStack(stackId)?.diffAssets, + }; let actualTemplate = actual[stackId].templates[templateId]; let expectedTemplate = expected[stackId].templates[templateId]; // if we are not verifying asset hashes then remove the specific // asset hashes from the templates so they are not part of the diff // comparison - if (!this.actualTestSuite.getOptionsForStack(stackId)?.diffAssets) { + if (!config.diffAssets) { actualTemplate = this.canonicalizeTemplate(actualTemplate, actual[stackId].assets); expectedTemplate = this.canonicalizeTemplate(expectedTemplate, expected[stackId].assets); } @@ -250,6 +253,7 @@ export class IntegSnapshotRunner extends IntegRunner { message: writable.data, stackName: templateId, testName: this.testName, + config, }); } } diff --git a/packages/@aws-cdk/integ-runner/lib/workers/common.ts b/packages/@aws-cdk/integ-runner/lib/workers/common.ts index fc8babd7a05a9..8a91212226548 100644 --- a/packages/@aws-cdk/integ-runner/lib/workers/common.ts +++ b/packages/@aws-cdk/integ-runner/lib/workers/common.ts @@ -245,6 +245,11 @@ export interface Diagnostic { * Additional messages to print */ readonly additionalMessages?: string[]; + + /** + * Relevant config options that were used for the integ test + */ + readonly config?: Record; } export function printSummary(total: number, failed: number): void { diff --git a/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts b/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts index 958380e5df5ef..0e425f3ca1bfb 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/snapshot-test-runner.test.ts @@ -65,6 +65,7 @@ describe('IntegTest runSnapshotTests', () => { reason: DiagnosticReason.SNAPSHOT_FAILED, testName: 'xxxxx.test-with-snapshot', message: expect.stringContaining('foobar'), + config: { diffAssets: true }, }), ])); expect(results.destructiveChanges).not.toEqual([{ @@ -96,6 +97,13 @@ describe('IntegTest runSnapshotTests', () => { reason: DiagnosticReason.SNAPSHOT_FAILED, testName: 'xxxxx.test-with-new-assets', message: expect.stringContaining('S3Key'), + config: { diffAssets: true }, + }), + expect.objectContaining({ + reason: DiagnosticReason.SNAPSHOT_FAILED, + testName: 'xxxxx.test-with-new-assets', + message: expect.stringContaining('TemplateURL'), + config: { diffAssets: true }, })])); }); @@ -110,6 +118,21 @@ describe('IntegTest runSnapshotTests', () => { testName: 'xxxxx.test-with-nested-stack', stackName: expect.stringContaining('teststacknested'), message: expect.stringContaining('AWS::SNS::Topic'), + config: { diffAssets: false }, + })])); + }); + + test('it will diff assets for nested stacks', () => { + // WHEN + const results = cdkMock.snapshotTest('xxxxx.test-with-nested-stack.js', 'xxxxx.test-with-asset-in-nested-stack.js.snapshot'); + + // THEN + expect(results.diagnostics).toEqual(expect.arrayContaining([expect.objectContaining({ + reason: DiagnosticReason.SNAPSHOT_FAILED, + testName: 'xxxxx.test-with-nested-stack', + stackName: expect.stringContaining('teststacknested'), + message: expect.stringContaining('S3Key'), + config: { diffAssets: true }, })])); }); }); @@ -124,6 +147,7 @@ describe('IntegTest runSnapshotTests', () => { reason: DiagnosticReason.SNAPSHOT_FAILED, testName: 'xxxxx.test-with-snapshot-assets', message: expect.stringContaining('Parameters'), + config: { diffAssets: true }, })])); }); diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json @@ -0,0 +1 @@ +{} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json index 04bcd2f5c1a4a..fce044c483fbb 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json @@ -26,6 +26,19 @@ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } + }, + "DIFFERENT_NESTED_STACK_HASH": { + "source": { + "path": "SomeNestedStackResourceA7AEBA6B.nested.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "DIFFERENT_NESTED_STACK_HASH.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } } }, "dockerImages": {} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json index 2beb6ac288dd2..8cd369391cf55 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json @@ -38,17 +38,18 @@ "S3Key": "be270bbdebe0851c887569796e3997437cca54ce86893ed94788500448e92825.zip" }, "Role": { - "Fn::GetAtt": [ - "MyFunction1ServiceRole9852B06B", - "Arn" - ] + "Fn::GetAtt": ["MyFunction1ServiceRole9852B06B", "Arn"] }, "Handler": "index.handler", "Runtime": "nodejs14.x" }, - "DependsOn": [ - "MyFunction1ServiceRole9852B06B" - ] + "DependsOn": ["MyFunction1ServiceRole9852B06B"] + }, + "SomeNestedStackResourceA7AEBA6B": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://s3.unknown-region.amazonaws.com/cdk-hnb659fds-assets-unknown-account-unknown-region/DIFFERENT_NESTED_STACK_HASH.json" + } } } } diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json @@ -0,0 +1 @@ +{} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json index 9fce39f0cb708..0dd89136db1b9 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json @@ -26,6 +26,19 @@ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } + }, + "6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9": { + "source": { + "path": "SomeNestedStackResourceA7AEBA6B.nested.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } } }, "dockerImages": {} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json index fe60c3f20c5c3..8abdf236198f1 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/cdk-integ.out.xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json @@ -49,6 +49,12 @@ "DependsOn": [ "MyFunction1ServiceRole9852B06B" ] + }, + "SomeNestedStackResourceA7AEBA6B": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://s3.unknown-region.amazonaws.com/cdk-hnb659fds-assets-unknown-account-unknown-region/6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9.json" + } } } } diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets.json new file mode 100644 index 0000000000000..91488886727c6 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/TestWithNestedStackDefaultTestDeployAssert9F80D3B6.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/cdk.out b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/integ.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/integ.json new file mode 100644 index 0000000000000..0e800e1a3fc32 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/integ.json @@ -0,0 +1,11 @@ +{ + "version": "21.0.0", + "testCases": { + "TestWithNestedStack/DefaultTest": { + "stacks": ["test-stack"], + "diffAssets": true, + "assertionStack": "TestWithNestedStack/DefaultTest/DeployAssert", + "assertionStackName": "TestWithNestedStackDefaultTestDeployAssert9F80D3B6" + } + } +} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/manifest.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/manifest.json new file mode 100644 index 0000000000000..e45aa1d70111d --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/manifest.json @@ -0,0 +1,141 @@ +{ + "version": "21.0.0", + "artifacts": { + "test-stack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "test-stack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "test-stack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "test-stack.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/e329bc2347c70a89ff078c2c93444d2b59a21f04cbf91afff7e9e5cab307b381.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "test-stack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "test-stack.assets" + ], + "metadata": { + "/test-stack/MyFunction/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyFunctionServiceRole3C357FF2" + } + ], + "/test-stack/MyFunction/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyFunction3BAA72D1" + } + ], + "/test-stack/nested/MyTopic/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyTopic86869434" + } + ], + "/test-stack/nested/MyNestedFunction/ServiceRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyNestedFunctionServiceRole56B518B8" + } + ], + "/test-stack/nested/MyNestedFunction/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "MyNestedFunctionA0269B76" + } + ], + "/test-stack/nested.NestedStack/nested.NestedStackResource": [ + { + "type": "aws:cdk:logicalId", + "data": "nestedNestedStacknestedNestedStackResource3DD143BF" + } + ], + "/test-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/test-stack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "test-stack" + }, + "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "TestWithNestedStackDefaultTestDeployAssert9F80D3B6": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "TestWithNestedStackDefaultTestDeployAssert9F80D3B6.assets" + ], + "metadata": { + "/TestWithNestedStack/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/TestWithNestedStack/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "TestWithNestedStack/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.assets.json new file mode 100644 index 0000000000000..06cae34119b66 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.assets.json @@ -0,0 +1,45 @@ +{ + "version": "21.0.0", + "files": { + "CHANGED_ASSET_HASH": { + "source": { + "path": "asset.CHANGED_ASSET_HASH", + "packaging": "zip" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "CHANGED_ASSET_HASH.zip", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "68d244d71d1a0f2942feda5bea8f07b26ee3b09b4e9df7eac4296dcaf8532234": { + "source": { + "path": "teststacknested140612C4.nested.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "68d244d71d1a0f2942feda5bea8f07b26ee3b09b4e9df7eac4296dcaf8532234.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + }, + "e329bc2347c70a89ff078c2c93444d2b59a21f04cbf91afff7e9e5cab307b381": { + "source": { + "path": "test-stack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "e329bc2347c70a89ff078c2c93444d2b59a21f04cbf91afff7e9e5cab307b381.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.template.json new file mode 100644 index 0000000000000..7418c1ab361ac --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/test-stack.template.json @@ -0,0 +1,115 @@ +{ + "Resources": { + "MyFunctionServiceRole3C357FF2": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "MyFunction3BAA72D1": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "foo" + }, + "Role": { + "Fn::GetAtt": [ + "MyFunctionServiceRole3C357FF2", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs14.x" + }, + "DependsOn": [ + "MyFunctionServiceRole3C357FF2" + ] + }, + "nestedNestedStacknestedNestedStackResource3DD143BF": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": { + "Fn::Join": [ + "", + [ + "https://s3.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "/68d244d71d1a0f2942feda5bea8f07b26ee3b09b4e9df7eac4296dcaf8532234.json" + ] + ] + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/teststacknested140612C4.nested.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/teststacknested140612C4.nested.template.json new file mode 100644 index 0000000000000..0e7b67cd27fe5 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/teststacknested140612C4.nested.template.json @@ -0,0 +1,63 @@ +{ + "Resources": { + "MyTopic86869434": { + "Type": "AWS::SNS::Topic", + "Properties": { + "DisplayName": "MyTopic" + } + }, + "MyNestedFunctionServiceRole56B518B8": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "MyNestedFunctionA0269B76": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "S3Key": "CHANGED_ASSET_HASH.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MyNestedFunctionServiceRole56B518B8", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs14.x" + }, + "DependsOn": [ + "MyNestedFunctionServiceRole56B518B8" + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/tree.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/tree.json new file mode 100644 index 0000000000000..8597834c8351d --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.js.snapshot/tree.json @@ -0,0 +1,387 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "test-stack": { + "id": "test-stack", + "path": "test-stack", + "children": { + "MyFunction": { + "id": "MyFunction", + "path": "test-stack/MyFunction", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "test-stack/MyFunction/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "test-stack/MyFunction/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "test-stack/MyFunction/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "test-stack/MyFunction/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "zipFile": "foo" + }, + "role": { + "Fn::GetAtt": [ + "MyFunctionServiceRole3C357FF2", + "Arn" + ] + }, + "handler": "index.handler", + "runtime": "nodejs14.x" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.Function", + "version": "0.0.0" + } + }, + "nested": { + "id": "nested", + "path": "test-stack/nested", + "children": { + "MyTopic": { + "id": "MyTopic", + "path": "test-stack/nested/MyTopic", + "children": { + "Resource": { + "id": "Resource", + "path": "test-stack/nested/MyTopic/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::SNS::Topic", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-sns.CfnTopic", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-sns.Topic", + "version": "0.0.0" + } + }, + "MyNestedFunction": { + "id": "MyNestedFunction", + "path": "test-stack/nested/MyNestedFunction", + "children": { + "ServiceRole": { + "id": "ServiceRole", + "path": "test-stack/nested/MyNestedFunction/ServiceRole", + "children": { + "ImportServiceRole": { + "id": "ImportServiceRole", + "path": "test-stack/nested/MyNestedFunction/ServiceRole/ImportServiceRole", + "constructInfo": { + "fqn": "@aws-cdk/core.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "test-stack/nested/MyNestedFunction/ServiceRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-iam.Role", + "version": "0.0.0" + } + }, + "Code": { + "id": "Code", + "path": "test-stack/nested/MyNestedFunction/Code", + "children": { + "Stage": { + "id": "Stage", + "path": "test-stack/nested/MyNestedFunction/Code/Stage", + "constructInfo": { + "fqn": "@aws-cdk/core.AssetStaging", + "version": "0.0.0" + } + }, + "AssetBucket": { + "id": "AssetBucket", + "path": "test-stack/nested/MyNestedFunction/Code/AssetBucket", + "constructInfo": { + "fqn": "@aws-cdk/aws-s3.BucketBase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-s3-assets.Asset", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "test-stack/nested/MyNestedFunction/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Lambda::Function", + "aws:cdk:cloudformation:props": { + "code": { + "s3Bucket": { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "s3Key": "b7826d21185e020066e56b133136e1082372d08cf21209a8823ac39710782f68.zip" + }, + "role": { + "Fn::GetAtt": [ + "MyNestedFunctionServiceRole56B518B8", + "Arn" + ] + }, + "handler": "index.handler", + "runtime": "nodejs14.x" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.CfnFunction", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-lambda.Function", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.NestedStack", + "version": "0.0.0" + } + }, + "nested.NestedStack": { + "id": "nested.NestedStack", + "path": "test-stack/nested.NestedStack", + "children": { + "nested.NestedStackResource": { + "id": "nested.NestedStackResource", + "path": "test-stack/nested.NestedStack/nested.NestedStackResource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudFormation::Stack", + "aws:cdk:cloudformation:props": { + "templateUrl": { + "Fn::Join": [ + "", + [ + "https://s3.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" + }, + "/68d244d71d1a0f2942feda5bea8f07b26ee3b09b4e9df7eac4296dcaf8532234.json" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.CfnStack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.154" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "test-stack/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "test-stack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "TestWithNestedStack": { + "id": "TestWithNestedStack", + "path": "TestWithNestedStack", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "TestWithNestedStack/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "TestWithNestedStack/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.154" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "TestWithNestedStack/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "TestWithNestedStack/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "TestWithNestedStack/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.154" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.ts b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.ts new file mode 100644 index 0000000000000..ff230f9f7e58e --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-asset-in-nested-stack.ts @@ -0,0 +1 @@ +/// !cdk-integ test-stack pragma:include-assets-hashes diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json @@ -0,0 +1 @@ +{} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json index 04bcd2f5c1a4a..fce044c483fbb 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.assets.json @@ -26,6 +26,19 @@ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } + }, + "DIFFERENT_NESTED_STACK_HASH": { + "source": { + "path": "SomeNestedStackResourceA7AEBA6B.nested.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "DIFFERENT_NESTED_STACK_HASH.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } } }, "dockerImages": {} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json index 2beb6ac288dd2..d564a1f01fa3a 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets-diff.js.snapshot/test-stack.template.json @@ -49,6 +49,12 @@ "DependsOn": [ "MyFunction1ServiceRole9852B06B" ] + }, + "SomeNestedStackResourceA7AEBA6B": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://s3.unknown-region.amazonaws.com/cdk-hnb659fds-assets-unknown-account-unknown-region/DIFFERENT_NESTED_STACK_HASH.json" + } } } } diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json new file mode 100644 index 0000000000000..0967ef424bce6 --- /dev/null +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/SomeNestedStackResourceA7AEBA6B.nested.template.json @@ -0,0 +1 @@ +{} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json index 9fce39f0cb708..0dd89136db1b9 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.assets.json @@ -26,6 +26,19 @@ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } + }, + "6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9": { + "source": { + "path": "SomeNestedStackResourceA7AEBA6B.nested.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } } }, "dockerImages": {} diff --git a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json index fe60c3f20c5c3..8abdf236198f1 100644 --- a/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json +++ b/packages/@aws-cdk/integ-runner/test/test-data/xxxxx.test-with-new-assets.js.snapshot/test-stack.template.json @@ -49,6 +49,12 @@ "DependsOn": [ "MyFunction1ServiceRole9852B06B" ] + }, + "SomeNestedStackResourceA7AEBA6B": { + "Type": "AWS::CloudFormation::Stack", + "Properties": { + "TemplateURL": "https://s3.unknown-region.amazonaws.com/cdk-hnb659fds-assets-unknown-account-unknown-region/6f980d09d47a00a7d5001feeb3994d1909bc5294e309d69bd4fbc815622f6fa9.json" + } } } }