Skip to content

Commit d8f5e2d

Browse files
authored
fix(ec2): securityGroups is mandatory in fromClusterAttributes (#25976)
The `securityGroups` is passed down to create a new `ec2.Connections`, where this property is already optional. Making it optional in `fromClusterAttributes` as well. Closes #11146 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d9427e2 commit d8f5e2d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/aws-cdk-lib/aws-ecs/lib/cluster.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,10 @@ export interface ClusterAttributes {
765765

766766
/**
767767
* The security groups associated with the container instances registered to the cluster.
768+
*
769+
* @default - no security groups
768770
*/
769-
readonly securityGroups: ec2.ISecurityGroup[];
771+
readonly securityGroups?: ec2.ISecurityGroup[];
770772

771773
/**
772774
* Specifies whether the cluster has EC2 instance capacity.

packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,20 @@ describe('cluster', () => {
13741374

13751375
});
13761376

1377+
test('Security groups are optonal for imported clusters', () => {
1378+
// GIVEN
1379+
const stack = new cdk.Stack();
1380+
const vpc = new ec2.Vpc(stack, 'Vpc');
1381+
1382+
const cluster = ecs.Cluster.fromClusterAttributes(stack, 'Cluster', {
1383+
clusterName: 'cluster-name',
1384+
vpc,
1385+
});
1386+
1387+
// THEN
1388+
expect(cluster.connections.securityGroups).toEqual([]);
1389+
});
1390+
13771391
test('Metric', () => {
13781392
// GIVEN
13791393
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)