-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the feature
Currently, CDK's L2 constructs allow setting security groups for NLBs, but this requires explicit configuration.
declare const sg1: ec2.ISecurityGroup;
const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc,
securityGroups: [sg1], // configure SG explicitly
});This was not originally intended - NLB security group support was implemented later, and the current specification exists to maintain backward compatibility.
However, when comparing NLBs without security groups to NLBs with security groups configured, the latter has significantly more advantages. Furthermore, once an NLB is created without security groups, it's impossible to add security group configuration later.
Therefore, I propose using feature flags to make security group configuration the default for NLBs in CDK.
Use Case
Basically, security groups should be configured when creating an NLB, but having to explicitly create and configure security groups feels cumbersome.
// Create an NLB with security group configuration
const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc,
});Proposed Solution
Create security group automatically when props.securityGroups is undefined.
Current implementation
this.connections = new ec2.Connections({ securityGroups: props.securityGroups });Proposed implementation (like ALB)
const securityGroups = [props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc: props.vpc,
description: `Automatically created Security Group for ELB ${Names.uniqueId(this)}`,
allowAllOutbound: false,
})];
this.connections = new ec2.Connections({ securityGroups });And add disableSecurityGroups prop to create legacy NLB.
const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc,
disableSecurityGroups: true,
});Other Information
No response
Acknowledgements
- I
maywill be able to implement this feature request - This feature might incur a breaking change
AWS CDK Library version (aws-cdk-lib)
2.198.0
AWS CDK CLI version
2.1015.0
Environment details (OS name and version, etc.)
macos