Skip to content

Commit

Permalink
fix(core): nested stacks does not report missing context #5594
Browse files Browse the repository at this point in the history
  • Loading branch information
Neta Nir committed Jan 3, 2020
1 parent 4223403 commit 749bccd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
31 changes: 29 additions & 2 deletions packages/@aws-cdk/aws-cloudformation/test/test.nested-stack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, haveResource, SynthUtils } from '@aws-cdk/assert';
import * as s3_assets from '@aws-cdk/aws-s3-assets';
import * as sns from '@aws-cdk/aws-sns';
import { App, CfnParameter, CfnResource, Construct, Stack } from '@aws-cdk/core';
import { App, CfnParameter, CfnResource, Construct, ContextProvider, Stack } from '@aws-cdk/core';
import * as fs from 'fs';
import { Test } from 'nodeunit';
import * as path from 'path';
Expand Down Expand Up @@ -872,5 +872,32 @@ export = {
}));

test.done();
}
},

'missing context in nested stack is reported if the context is not available'(test: Test) {
// GIVEN
const app = new App();
const stack = new Stack(app, 'ParentStack', { env: { account: '1234account', region: 'us-east-44' } });
const nestedStack = new NestedStack(stack, 'nested');
const provider = 'dummyProvider';
const expectedKey = ContextProvider.getKey(nestedStack, {
provider
}).key;

// WHEN
ContextProvider.getValue(nestedStack, {
provider,
dummyValue: ['dummy1a', 'dummy1b', 'dummy1c'],
});

// THEN: missing context is reported in the cloud assembly
const asm = app.synth();
const missing = asm.manifest.missing;

test.ok(missing && missing.find(m => {
return (m.key === expectedKey);
}));

test.done();
},
};
9 changes: 4 additions & 5 deletions packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,17 @@ export class Stack extends Construct implements ITaggable {
const text = JSON.stringify(this._toCloudFormation(), undefined, 2);
fs.writeFileSync(outPath, text);

for (const ctx of this._missingContext) {
builder.addMissing(ctx);
}

// if this is a nested stack, do not emit it as a cloud assembly artifact (it will be registered as an s3 asset instead)
if (this.nested) {
return;
}

const deps = this.dependencies.map(s => s.artifactId);
const meta = this.collectMetadata();

// backwards compatibility since originally artifact ID was always equal to
// stack name the stackName attribute is optional and if it is not specified
// the CLI will use the artifact ID as the stack name. we *could have*
Expand All @@ -823,10 +826,6 @@ export class Stack extends Construct implements ITaggable {
dependencies: deps.length > 0 ? deps : undefined,
metadata: Object.keys(meta).length > 0 ? meta : undefined,
});

for (const ctx of this._missingContext) {
builder.addMissing(ctx);
}
}

/**
Expand Down

0 comments on commit 749bccd

Please sign in to comment.