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

aws-ec2: Export NatGatewayProvider #28372

Closed
1 of 2 tasks
Closed
1 of 2 tasks
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@crh23
Copy link
Contributor

crh23 commented Dec 14, 2023

Describe the feature

(originally posted as a discussion)

There are two implementations of NatProvider: NatGatewayProvider and NatInstanceProvider.

Of the two, only NatInstanceProvider is exported. Both are usable through aws_ec2.NatProvider.instance() and aws_ec2.NatProvider.gateway() respectively, but since only NatInstanceProvider is exported the docs indicate that NatProvider is only implemented by NatInstanceProvider.

I suggest that NatGatewayProvider also be exported, so that both providers are available through both interfaces and so the docs correctly reflect the two available implementations of NatProvider.

Use Case

No real new functionality is exposed, except the ability to instantiate NatGatewayProvider directly instead of using the static method of NatProvider. The main advantage is the implied update to the docs.

Proposed Solution

I think this is as simple as inserting an export at the start of L217

/**
* Provider for NAT Gateways
*/
class NatGatewayProvider extends NatProvider {
private gateways: PrefSet<string> = new PrefSet<string>();
constructor(private readonly props: NatGatewayProps = {}) {
super();
}
public configureNat(options: ConfigureNatOptions) {
if (
this.props.eipAllocationIds != null
&& !Token.isUnresolved(this.props.eipAllocationIds)
&& this.props.eipAllocationIds.length < options.natSubnets.length
) {
throw new Error(`Not enough NAT gateway EIP allocation IDs (${this.props.eipAllocationIds.length} provided) for the requested subnet count (${options.natSubnets.length} needed).`);
}
// Create the NAT gateways
let i = 0;
for (const sub of options.natSubnets) {
const eipAllocationId = this.props.eipAllocationIds ? pickN(i, this.props.eipAllocationIds) : undefined;
const gateway = sub.addNatGateway(eipAllocationId);
this.gateways.add(sub.availabilityZone, gateway.ref);
i++;
}
// Add routes to them in the private subnets
for (const sub of options.privateSubnets) {
this.configureSubnet(sub);
}
}
public configureSubnet(subnet: PrivateSubnet) {
const az = subnet.availabilityZone;
const gatewayId = this.gateways.pick(az);
subnet.addRoute('DefaultRoute', {
routerType: RouterType.NAT_GATEWAY,
routerId: gatewayId,
enablesInternetConnectivity: true,
});
}
public get configuredGateways(): GatewayConfig[] {
return this.gateways.values().map(x => ({ az: x[0], gatewayId: x[1] }));
}
}

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.115.0

Environment details (OS name and version, etc.)

Windows 10

@crh23 crh23 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Dec 14, 2023
@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 14, 2023
@mergify mergify bot closed this as completed in #28810 Jul 31, 2024
@mergify mergify bot closed this as completed in fbc28bc Jul 31, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.