Skip to content

Commit f2e5dbf

Browse files
committed
Convert InstanceType to a CSV
This is super ugly internally, but it presents a possibly OK interface to users of the stack. Users can specify 1-4 instance types separated by commas. When launching OnDemand instances, the types will be attempted in priority order. When launching spot instances (if they're enabled) all types are considered. Internally, this is implemented by appending 3 commas to the InstanceType and re-splitting it (to ensure there's ALWAYS at least 4 list items passed to !Select.
1 parent 19710cc commit f2e5dbf

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

templates/aws-stack.yml

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ Metadata:
3939
- ImageId
4040
- ImageIdParameter
4141
- InstanceType
42-
- InstanceType2
43-
- InstanceType3
44-
- InstanceType4
4542
- AgentsPerInstance
4643
- KeyName
4744
- SecretsBucket
@@ -207,7 +204,7 @@ Parameters:
207204
Default: ""
208205

209206
InstanceType:
210-
Description: Instance type
207+
Description: Instance type. Comma separated list with 1-4 instance types. The order is a prioritised preference for launching OnDemand instances, and an non-prioritised list of types to consider for Spot Instances (where used).
211208
Type: String
212209
Default: t3.large
213210
MinLength: 1
@@ -223,21 +220,6 @@ Parameters:
223220
Type: Number
224221
Default: 0
225222

226-
InstanceType2:
227-
Description: The secondary instance type to use when requesting mixed instances. Omit this parmameter to only request 1 instance type.
228-
Type: String
229-
Default: ""
230-
231-
InstanceType3:
232-
Description: The tertiary instance type to use when requesting mixed instances. Omit this parmameter to only request 2 instance types.
233-
Type: String
234-
Default: ""
235-
236-
InstanceType4:
237-
Description: The quaternary instance type to use when requesting mixed instances. Omit this parmameter to only request 3 instance types.
238-
Type: String
239-
Default: ""
240-
241223
OnDemandPercentage:
242224
Description: Percentage of total instances that should launch as OnDemand. Reduce this to use some Spot Instances when they're available.
243225
Type: Number
@@ -465,13 +447,13 @@ Conditions:
465447
!Equals [ !Ref RootVolumeName, "" ]
466448

467449
UseInstanceType2:
468-
!Not [ !Equals [ !Ref InstanceType2, ""] ]
450+
!Not [ !Equals [ !Select [ "1", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
469451

470452
UseInstanceType3:
471-
!Not [ !Equals [ !Ref InstanceType3, ""] ]
453+
!Not [ !Equals [ !Select [ "2", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
472454

473455
UseInstanceType4:
474-
!Not [ !Equals [ !Ref InstanceType4, ""] ]
456+
!Not [ !Equals [ !Select [ "3", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ], ""] ]
475457

476458
UseManagedPolicyARN:
477459
!Not [ !Equals [ !Join [ "", !Ref ManagedPolicyARN ], "" ] ]
@@ -830,7 +812,7 @@ Resources:
830812
KeyName: !If [ "HasKeyName", !Ref KeyName, !Ref 'AWS::NoValue' ]
831813
IamInstanceProfile:
832814
Arn: !GetAtt "IAMInstanceProfile.Arn"
833-
InstanceType: !Ref InstanceType
815+
InstanceType: !Select [ "0", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
834816
ImageId: !If [ HasImageId, !Ref ImageId, !If [ HasImageIdParameter, !GetAtt ImageIdParameterStack.Outputs.ImageId, !FindInMap [ AWSRegion2AMI, !Ref 'AWS::Region', !Ref InstanceOperatingSystem ] ] ]
835817
BlockDeviceMappings:
836818
- DeviceName: !If [ UseDefaultRootVolumeName, !If [ UseWindowsAgents, /dev/sda1, /dev/xvda ], !Ref RootVolumeName ]
@@ -944,18 +926,18 @@ Resources:
944926
LaunchTemplateId: !Ref AgentLaunchTemplate
945927
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
946928
Overrides:
947-
- InstanceType: !Ref InstanceType
929+
- InstanceType: !Select [ "0", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
948930
- InstanceType: !If
949931
- UseInstanceType2
950-
- !Ref InstanceType2
932+
- !Select [ "1", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
951933
- !Ref "AWS::NoValue"
952934
- InstanceType: !If
953935
- UseInstanceType3
954-
- !Ref InstanceType3
936+
- !Select [ "2", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
955937
- !Ref "AWS::NoValue"
956938
- InstanceType: !If
957939
- UseInstanceType4
958-
- !Ref InstanceType4
940+
- !Select [ "3", !Split [ ",", !Join [ ",", [ !Ref InstanceType, "", "", "" ] ] ] ]
959941
- !Ref "AWS::NoValue"
960942
MinSize: !Ref MinSize
961943
MaxSize: !Ref MaxSize

0 commit comments

Comments
 (0)