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

fix(ecs): autoscalingGroup attribute does not exist on ImportedCluster #29244

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,11 @@ class ImportedCluster extends Resource implements ICluster {
*/
public readonly hasEc2Capacity: boolean;

/**
* Autoscaling group of the cluster
*/
readonly autoscalingGroup?: autoscaling.IAutoScalingGroup;
msambol marked this conversation as resolved.
Show resolved Hide resolved

/**
* Cloudmap namespace created in the cluster
*/
Expand All @@ -878,6 +883,7 @@ class ImportedCluster extends Resource implements ICluster {
this.hasEc2Capacity = props.hasEc2Capacity !== false;
this._defaultCloudMapNamespace = props.defaultCloudMapNamespace;
this._executeCommandConfiguration = props.executeCommandConfiguration;
this.autoscalingGroup = props.autoscalingGroup;

this.clusterArn = props.clusterArn ?? Stack.of(this).formatArn({
service: 'ecs',
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,26 @@ describe('cluster', () => {
expect(cluster.connections.securityGroups).toEqual([]);
});

test('Can import autoscaling groups', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const autoscalingGroup = new autoscaling.AutoScalingGroup(stack, 'asgal2', {
vpc,
instanceType: new ec2.InstanceType('bogus'),
machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
});

const cluster = ecs.Cluster.fromClusterAttributes(stack, 'Cluster', {
clusterName: 'cluster-name',
vpc,
autoscalingGroup,
});

// THEN
expect(cluster.autoscalingGroup).toEqual(autoscalingGroup);
});

test('Metric', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading