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

vpc construct: only try setting context if unset #2438

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/dirty-cherries-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/cdk": patch
---

Fix bug preventing creation of multiple VPCs in single stack
9 changes: 9 additions & 0 deletions src/constructs/vpc/vpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ describe("The GuVpc construct", () => {
new GuVpc(stack, "MyVpc");
expect(Template.fromStack(stack).toJSON()).toMatchSnapshot();
});

it("should be possible to create two vpcs in the same stack", () => {
const stack = simpleGuStackForTesting({
stack: "test-stack",
env: { region: "eu-west-1", account: "000000000000" },
});
new GuVpc(stack, "MyVpc");
new GuVpc(stack, "MyOtherVpc");
});
});
10 changes: 5 additions & 5 deletions src/constructs/vpc/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class GuVpc extends Vpc {
);
}

node.setContext(`availability-zones:account=${account}:region=eu-west-1`, [
"eu-west-1a",
"eu-west-1b",
"eu-west-1c",
]);
const contextKey = `availability-zones:account=${account}:region=eu-west-1`;
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR necessarily, but I wonder why the region has been hard-coded here, rather than this.region?


if (node.tryGetContext(contextKey) === undefined) {
node.setContext(contextKey, ["eu-west-1a", "eu-west-1b", "eu-west-1c"]);
}
}

constructor(scope: GuStack, id: string, props?: GuVpcProps) {
Expand Down