Skip to content

Commit 4dc5b28

Browse files
committed
Switch the asg between launch template specification, and mixed instance policy. Add a warm pool rule assertion that if enabled, a single instance is used and spot is not used
1 parent e0cded6 commit 4dc5b28

File tree

1 file changed

+77
-38
lines changed

1 file changed

+77
-38
lines changed

templates/aws-stack.yml

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,22 @@ Parameters:
231231

232232
InstanceType:
233233
Description: Instance type. Comma-separated list with 1-4 instance types. The order is a prioritized preference for launching OnDemand instances, and a non-prioritized list of types to consider for Spot Instances (where used).
234-
Type: String
234+
Type: CommaDelimitedList
235235
Default: t3.large
236236
MinLength: 1
237237
AllowedPattern: "^[\\w\\.]+(,[\\w\\.]*){0,3}$"
238238
ConstraintDescription: "must contain 1-4 instance types separated by commas. No space before/after the comma."
239239

240+
InstanceTypes:
241+
Description: How many instance types are specified in InstanceType
242+
Type: String
243+
Default: "1"
244+
AllowedValues:
245+
- "1"
246+
- "2"
247+
- "3"
248+
- "4"
249+
240250
SpotPrice:
241251
Description: Maximum spot price to use for the instances, in instance cost per hour. Values >0 will result in 100% of instances being spot. 0 means only use normal (non-spot) instances. This parameter is deprecated - we recommend setting to 0 and using OnDemandPercentage to opt into spot instances.
242252
Type: String
@@ -462,6 +472,19 @@ Rules:
462472
- !Ref BuildkiteAgentTokenParameterStorePath
463473
- ""
464474
AssertDescription: "You must provide BuildkiteAgentToken or BuildkiteAgentTokenParameterStorePath"
475+
WarmPoolInstanceTypeCompatible:
476+
RuleCondition:
477+
# If warm pool is enabled
478+
!Not [ !Equals [ !Ref WarmPoolMinSize, 0 ] ]
479+
Assertions:
480+
# There must only be one instance type
481+
- Assert:
482+
!Equals [ !Ref InstanceTypes, "1" ]
483+
# Spot must not be used
484+
- Assert:
485+
!And
486+
- !Equals [ !Ref SpotPrice, 0 ]
487+
- !Equals [ !Ref OnDemandPercentage, 100 ]
465488

466489
Outputs:
467490
VpcId:
@@ -536,14 +559,21 @@ Conditions:
536559
UseDefaultRootVolumeName:
537560
!Equals [ !Ref RootVolumeName, "" ]
538561

539-
UseInstanceType2:
540-
!Not [ !Equals [ !Select [ "1", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
562+
# If using spot, or multiple instances we need to use a MixedInstancesPolicy
563+
UseMixedInstancesPolicy:
564+
!Or
565+
- !Not [ !Equals [ !Ref SpotPrice, 0 ] ]
566+
- !Not [ !Equals [ !Ref OnDemandPercentage, 100 ] ]
567+
- !Condition UseInstanceType2
568+
- !Condition UseInstanceType3
569+
- !Condition UseInstanceType4
541570

571+
UseInstanceType2:
572+
!Equals [ !Ref InstanceTypes, "2" ]
542573
UseInstanceType3:
543-
!Not [ !Equals [ !Select [ "2", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
544-
574+
!Equals [ !Ref InstanceTypes, "3" ]
545575
UseInstanceType4:
546-
!Not [ !Equals [ !Select [ "3", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
576+
!Equals [ !Ref InstanceTypes, "4" ]
547577

548578
UseManagedPolicyARN:
549579
!Not [ !Equals [ !Join [ "", !Ref ManagedPolicyARN ], "" ] ]
@@ -587,15 +617,15 @@ Conditions:
587617

588618
UsingArmInstances:
589619
!Or
590-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "m6g" ]
591-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "m6gd" ]
592-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "t4g" ]
593-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "a1" ]
594-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "c6g" ]
595-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "c6gd" ]
596-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "c6gn" ]
597-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "r6g" ]
598-
- !Equals [ !Select [ 0, !Split [ ".", !Ref InstanceType ] ], "r6gd" ]
620+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "m6g" ]
621+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "m6gd" ]
622+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "t4g" ]
623+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "a1" ]
624+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "c6g" ]
625+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "c6gd" ]
626+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "c6gn" ]
627+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "r6g" ]
628+
- !Equals [ !Select [ 0, !Split [ ".", !Select [ 0, !Ref InstanceType ] ] ], "r6gd" ]
599629

600630
UseMaxInstanceLifetime:
601631
!Not [ !Equals [ !Ref MaxInstanceLifetime, 0 ] ]
@@ -912,7 +942,7 @@ Resources:
912942
KeyName: !If [ "HasKeyName", !Ref KeyName, !Ref 'AWS::NoValue' ]
913943
IamInstanceProfile:
914944
Arn: !GetAtt "IAMInstanceProfile.Arn"
915-
InstanceType: !Select [ "0", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
945+
InstanceType: !Select [ 0, !Ref InstanceType ]
916946
MetadataOptions:
917947
HttpTokens: !Ref IMDSv2Tokens
918948
# Allow containers using a Docker network on the host to receive IDMSv2 responses
@@ -1056,29 +1086,38 @@ Resources:
10561086
- VpcComplete
10571087
Properties:
10581088
VPCZoneIdentifier: !If [ "CreateVpcResources", [ !Ref Subnet0, !Ref Subnet1 ], !Ref Subnets ]
1089+
LaunchTemplate:
1090+
!If
1091+
- !Not [ UseMixedInstancesPolicy ]
1092+
- LaunchTemplateId: !Ref AgentLaunchTemplate
1093+
Version: !GetAtt AgentLaunchTemplate.LatestVersionNumber
1094+
- !Ref AWS::NoValue
10591095
MixedInstancesPolicy:
1060-
InstancesDistribution:
1061-
OnDemandPercentageAboveBaseCapacity: !If [ SpotPriceSet, 0, !Ref OnDemandPercentage ]
1062-
SpotAllocationStrategy: capacity-optimized
1063-
SpotMaxPrice: !If [SpotPriceSet, !Ref SpotPrice, !Ref "AWS::NoValue"]
1064-
LaunchTemplate:
1065-
LaunchTemplateSpecification:
1066-
LaunchTemplateId: !Ref AgentLaunchTemplate
1067-
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
1068-
Overrides:
1069-
- InstanceType: !Select [ "0", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
1070-
- !If
1071-
- UseInstanceType2
1072-
- InstanceType: !Select [ "1", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
1073-
- !Ref "AWS::NoValue"
1074-
- !If
1075-
- UseInstanceType3
1076-
- InstanceType: !Select [ "2", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
1077-
- !Ref "AWS::NoValue"
1078-
- !If
1079-
- UseInstanceType4
1080-
- InstanceType: !Select [ "3", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
1081-
- !Ref "AWS::NoValue"
1096+
!If
1097+
- UseMixedInstancesPolicy
1098+
- InstancesDistribution:
1099+
OnDemandPercentageAboveBaseCapacity: !If [ SpotPriceSet, 0, !Ref OnDemandPercentage ]
1100+
SpotAllocationStrategy: capacity-optimized
1101+
SpotMaxPrice: !If [SpotPriceSet, !Ref SpotPrice, !Ref "AWS::NoValue"]
1102+
LaunchTemplate:
1103+
LaunchTemplateSpecification:
1104+
LaunchTemplateId: !Ref AgentLaunchTemplate
1105+
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
1106+
Overrides:
1107+
- InstanceType: !Select [ 0, !Ref InstanceType ]
1108+
- !If
1109+
- UseInstanceType2
1110+
- InstanceType: !Select [ 1, !Ref InstanceType ]
1111+
- !Ref "AWS::NoValue"
1112+
- !If
1113+
- UseInstanceType3
1114+
- InstanceType: !Select [ 2, !Ref InstanceType ]
1115+
- !Ref "AWS::NoValue"
1116+
- !If
1117+
- UseInstanceType4
1118+
- InstanceType: !Select [ 3, !Ref InstanceType ]
1119+
- !Ref "AWS::NoValue"
1120+
- !Ref AWS::NoValue
10821121
MinSize: !Ref MinSize
10831122
MaxSize: !Ref MaxSize
10841123
Cooldown: 60

0 commit comments

Comments
 (0)