Skip to content

Commit

Permalink
Fix VPC support for Auto subnet layout strategy (#1355)
Browse files Browse the repository at this point in the history
The awsx.ec2.Vpc resource supports three subnet layout strategies: Auto,
Exact, and Legacy. Consider the following program that does not specify
the subnet specs:

    new awsx.ec2.Vpc("vpc", {
        subnetStrategy: "Auto",
    });

Prior to this change, the code would implicitly use the Legacy strategy
for this program even though Auto is requested. This is now fixed. The
Auto strategy already supports allocating subnets without any explicit
specs provided.
  • Loading branch information
t0yv0 authored Aug 5, 2024
1 parent 82ec192 commit 6fb976e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions awsx/ec2/vpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,9 @@ describe("picking subnet allocator", () => {
expect(a.allocator).toBe("LegacyAllocator");
});

// This behavior is suspect as NewAllocator supports working without any subnet specs defined.
it("picks legacy allocator for the auto strategy with no specs", () => {
it("picks NewAllocator for the auto strategy with no specs", () => {
const a = Vpc.pickSubnetAllocator(undefined, "Auto");
expect(a.allocator).toBe("LegacyAllocator");
expect(a.allocator).toBe("NewAllocator");
});

// This behavior looks like a degenerate case perhaps marking the strategy as invalid and failing could be preferable.
Expand Down
7 changes: 6 additions & 1 deletion awsx/ec2/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,12 @@ export class Vpc extends schema.Vpc<VpcData> {
):
| { allocator: "LegacyAllocator" | "NewAllocator" }
| { allocator: "ExplicitAllocator"; specs: ExplicitSubnetSpecInputs[] } {
if (parsedSpecs === undefined || subnetStrategy === "Legacy") {
if (parsedSpecs === undefined) {
return subnetStrategy === "Auto"
? { allocator: "NewAllocator" }
: { allocator: "LegacyAllocator" };
}
if (subnetStrategy === "Legacy") {
return { allocator: "LegacyAllocator" };
}
if (parsedSpecs.isExplicitLayout) {
Expand Down

0 comments on commit 6fb976e

Please sign in to comment.