diff --git a/api/backend/ecs/environment_manager.go b/api/backend/ecs/environment_manager.go index 7cb8d690a..1837f695d 100644 --- a/api/backend/ecs/environment_manager.go +++ b/api/backend/ecs/environment_manager.go @@ -201,8 +201,8 @@ func (e *ECSEnvironmentManager) CreateEnvironment( keyPair := config.AWSKeyPair() launchConfigurationName := ecsEnvironmentID.LaunchConfigurationName() volSizes := make(map[string]int) - if operatingSystem == "linux" { - volSizes["/dev/xvda"] = 30; + if operatingSystem == "linux" { + volSizes["/dev/xvda"] = 30 } else { volSizes["/dev/sda1"] = 200 } @@ -219,21 +219,16 @@ func (e *ECSEnvironmentManager) CreateEnvironment( ); err != nil { return nil, err } - - //set the default value + maxCountToSetInASG := maxClusterCount if minClusterCount > maxClusterCount { - maxClusterCount = minClusterCount - } - if targetCapSize == 0 { - targetCapSize = 100 + maxCountToSetInASG = minClusterCount } - if err := e.AutoScaling.CreateAutoScalingGroup( ecsEnvironmentID.AutoScalingGroupName(), launchConfigurationName, config.AWSPrivateSubnets(), minClusterCount, - maxClusterCount, + maxCountToSetInASG, ); err != nil { return nil, err } diff --git a/common/aws/ecs/ecs.go b/common/aws/ecs/ecs.go index 1900a6b4e..30492d188 100644 --- a/common/aws/ecs/ecs.go +++ b/common/aws/ecs/ecs.go @@ -720,13 +720,28 @@ func (this *ECS) CreateCapacityProvider(CapacityProviderName string, AsgArn stri func (this *ECS) CreateCluster(clusterName string, asgArn string, maxScalingSize, minScalingSize, targetCapSize int) (*Cluster, error) { - capacityProvider, err := this.CreateCapacityProvider(clusterName, asgArn, maxScalingSize, minScalingSize, targetCapSize) - if err != nil { - return nil, err - } - input := &ecs.CreateClusterInput{ - ClusterName: aws.String(clusterName), - CapacityProviders: []*string{aws.String(*capacityProvider.Name)}, + var input *ecs.CreateClusterInput + //ASG section. If CapSize and maxClusterCount equals to default 0. + classicASGEnabled := targetCapSize == 0 && maxScalingSize == 0 + if classicASGEnabled { + input = &ecs.CreateClusterInput{ + ClusterName: aws.String(clusterName), + } + } else { //If capacitor provider is enabled. + if minScalingSize > maxScalingSize { + maxScalingSize = minScalingSize + } + if targetCapSize == 0 { + targetCapSize = 100 + } + capacityProvider, err := this.CreateCapacityProvider(clusterName, asgArn, maxScalingSize, minScalingSize, targetCapSize) + if err != nil { + return nil, err + } + input = &ecs.CreateClusterInput{ + ClusterName: aws.String(clusterName), + CapacityProviders: []*string{aws.String(*capacityProvider.Name)}, + } } connection, err := this.Connect()