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(core): reusing StackSynthesizer leads to unsynthesized Stacks #11635

Merged
merged 2 commits into from
Nov 24, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export class DefaultStackSynthesizer extends StackSynthesizer {
}

public bind(stack: Stack): void {
if (this._stack !== undefined) {
throw new Error('A StackSynthesizer can only be used for one Stack: create a new instance to use with a different Stack');
}

this._stack = stack;

const qualifier = this.props.qualifier ?? stack.node.tryGetContext(BOOTSTRAP_QUALIFIER_CONTEXT) ?? DefaultStackSynthesizer.DEFAULT_QUALIFIER;
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/core/lib/stack-synthesizers/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class LegacyStackSynthesizer extends StackSynthesizer {
private readonly addedImageAssets = new Set<string>();

public bind(stack: Stack): void {
if (this.stack !== undefined) {
throw new Error('A StackSynthesizer can only be used for one Stack: create a new instance to use with a different Stack');
}
this.stack = stack;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/core/lib/stack-synthesizers/nested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class NestedStackSynthesizer extends StackSynthesizer {
}

public bind(stack: Stack): void {
if (this.stack !== undefined) {
throw new Error('A StackSynthesizer can only be used for one Stack: create a new instance to use with a different Stack');
}
this.stack = stack;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ nodeunitShim({

test.done();
},

'cannot use same synthesizer for multiple stacks'(test: Test) {
// GIVEN
const synthesizer = new DefaultStackSynthesizer();

// WHEN
new Stack(app, 'Stack2', { synthesizer });
test.throws(() => {
new Stack(app, 'Stack3', { synthesizer });
}, /A StackSynthesizer can only be used for one Stack/);
test.done();
},
});

/**
Expand Down