-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit aws.ec2.Vpc to use IPAM-allocated cidrBlock ranges (#1352)
Fixes issues with supporting the ipv4IpamPoolId parameter that ties a VPC to an IPAM pool. You should now be able to write the following to allows IPAM to allocate and manage a cidrBlock range. The VPC component now uses that dynamically allocated block to automatically configure subnets. ```typescript new awsx.ec2.Vpc("myVpc", { ipv4IpamPoolId: myVpcIpamPool.id, ipv4NetmaskLength: 24, subnetStrategy: "Auto", }); ``` It is also possible to constrain the allocated subnets with subnetSpecs, while still using IPAM to manage the overall cidrBlock range: ```typescript new awsx.ec2.Vpc("myVpc", { numberOfAvailabilityZones: 3, subnetStrategy: "Auto", ipv4IpamPoolId: myVpcIpamPool.id, ipv4NetmaskLength: 22, subnetSpecs: [ { type: "Private", name: "private", cidrMask: 25, }, { type: "Public", name: "public", cidrMask: 27, }, ], tags: tags, }); ``` Fixes #872 Note that `subnetStrategy: "Auto"` is required with this functionality, and "Legacy" strategy is not supported.
- Loading branch information
Showing
22 changed files
with
813 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as pulumi from "@pulumi/pulumi"; | ||
|
||
import { SubnetTypeInputs } from "../schema-types"; | ||
|
||
export interface SubnetSpec { | ||
cidrBlock: string; | ||
type: SubnetTypeInputs; | ||
azName: string; | ||
subnetName: string; | ||
tags?: pulumi.Input<{ | ||
[key: string]: pulumi.Input<string>; | ||
}>; | ||
} | ||
|
||
// Like SubnetSpec, but cidrBlock may not be fully known yet. This type supports scenarios where the cidrBlock is | ||
// allocated by IPAM and is only known after the underlying VPC provisions. | ||
export type SubnetSpecPartial = Omit<SubnetSpec, "cidrBlock"> & { cidrBlock: pulumi.Input<string> }; | ||
|
||
// Runs check(specs) immediately if all specs are fully known, otherwise defers validation into the apply layer and | ||
// makes sure that validation is resolved before cidrBlock fields resolve. | ||
export function validatePartialSubnetSpecs( | ||
specs: SubnetSpecPartial[], | ||
check: (specs: SubnetSpec[]) => void, | ||
): SubnetSpecPartial[] { | ||
const promptSpecs = detectPromptSubnetSpecs(specs); | ||
if (promptSpecs) { | ||
check(promptSpecs); | ||
return specs; | ||
} | ||
|
||
const checked: pulumi.Output<SubnetSpec[]> = pulumi.output(specs).apply((xs) => { | ||
check(xs); | ||
return xs; | ||
}); | ||
return specs.map((s, index) => ({ ...s, cidrBlock: checked.apply((cs) => cs[index].cidrBlock) })); | ||
} | ||
|
||
function detectPromptSubnetSpecs(specs: SubnetSpecPartial[]): SubnetSpec[] | undefined { | ||
if (specs.every((s) => typeof s.cidrBlock === "string")) { | ||
return specs.map((s) => { | ||
const cidrBlock: string = typeof s.cidrBlock === "string" ? s.cidrBlock : ""; | ||
return { ...s, cidrBlock }; | ||
}); | ||
} else { | ||
return undefined; | ||
} | ||
} |
Oops, something went wrong.