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.
#27978
#28494
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
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
Describe the feature
Currently, CDK's L2 constructs allow setting security groups for NLBs, but this requires explicit configuration.
This was not originally intended - NLB security group support was implemented later, and the current specification exists to maintain backward compatibility.
#27978
#28494
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.
Proposed Solution
Create security group automatically when
props.securityGroupsisundefined.Current implementation
Proposed implementation (like ALB)
And add
disableSecurityGroupsprop to create legacy NLB.Other Information
No response
Acknowledgements
maywill be able to implement this feature requestAWS CDK Library version (aws-cdk-lib)
2.198.0
AWS CDK CLI version
2.1015.0
Environment details (OS name and version, etc.)
macos