@@ -22,6 +22,7 @@ import (
22
22
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
23
23
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
24
24
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
25
+ "k8s.io/kops/util/pkg/maps"
25
26
)
26
27
27
28
type terraformLaunchTemplateNetworkInterface struct {
@@ -262,55 +263,39 @@ func (t *LaunchTemplate) RenderTerraform(target *terraform.TerraformTarget, a, e
262
263
}
263
264
}
264
265
}
266
+
265
267
devices , err := e .buildRootDevice (cloud )
266
268
if err != nil {
267
269
return err
268
270
}
269
- for n , x := range devices {
270
- tf .BlockDeviceMappings = append (tf .BlockDeviceMappings , & terraformLaunchTemplateBlockDevice {
271
- DeviceName : fi .PtrTo (n ),
272
- EBS : []* terraformLaunchTemplateBlockDeviceEBS {
273
- {
274
- DeleteOnTermination : fi .PtrTo (true ),
275
- Encrypted : x .EbsEncrypted ,
276
- KmsKeyID : x .EbsKmsKey ,
277
- IOPS : x .EbsVolumeIops ,
278
- Throughput : x .EbsVolumeThroughput ,
279
- VolumeSize : x .EbsVolumeSize ,
280
- VolumeType : fi .PtrTo (string (x .EbsVolumeType )),
281
- },
282
- },
283
- })
271
+
272
+ devicesKeys := maps .SortedKeys (devices )
273
+ for _ , key := range devicesKeys {
274
+ terraformLaunchTemplateBlockDevice := createTerraformLaunchTemplateBlockDevice (key , devices [key ])
275
+ tf .BlockDeviceMappings = append (tf .BlockDeviceMappings , terraformLaunchTemplateBlockDevice )
284
276
}
277
+
285
278
additionals , err := buildAdditionalDevices (e .BlockDeviceMappings )
286
279
if err != nil {
287
280
return err
288
281
}
289
- for n , x := range additionals {
290
- tf .BlockDeviceMappings = append (tf .BlockDeviceMappings , & terraformLaunchTemplateBlockDevice {
291
- DeviceName : fi .PtrTo (n ),
292
- EBS : []* terraformLaunchTemplateBlockDeviceEBS {
293
- {
294
- DeleteOnTermination : fi .PtrTo (true ),
295
- Encrypted : x .EbsEncrypted ,
296
- IOPS : x .EbsVolumeIops ,
297
- Throughput : x .EbsVolumeThroughput ,
298
- KmsKeyID : x .EbsKmsKey ,
299
- VolumeSize : x .EbsVolumeSize ,
300
- VolumeType : fi .PtrTo (string (x .EbsVolumeType )),
301
- },
302
- },
303
- })
282
+
283
+ additionalsKeys := maps .SortedKeys (additionals )
284
+ for _ , key := range additionalsKeys {
285
+ terraformLaunchTemplateBlockDevice := createTerraformLaunchTemplateBlockDevice (key , additionals [key ])
286
+ tf .BlockDeviceMappings = append (tf .BlockDeviceMappings , terraformLaunchTemplateBlockDevice )
304
287
}
305
288
306
289
devices , err = buildEphemeralDevices (cloud , fi .ValueOf (e .InstanceType ))
307
290
if err != nil {
308
291
return err
309
292
}
310
- for n , x := range devices {
293
+
294
+ devicesKeys = maps .SortedKeys (devices )
295
+ for _ , key := range devicesKeys {
311
296
tf .BlockDeviceMappings = append (tf .BlockDeviceMappings , & terraformLaunchTemplateBlockDevice {
312
- VirtualName : x .VirtualName ,
313
- DeviceName : fi .PtrTo (n ),
297
+ VirtualName : devices [ key ] .VirtualName ,
298
+ DeviceName : fi .PtrTo (key ),
314
299
})
315
300
}
316
301
@@ -328,3 +313,20 @@ func (t *LaunchTemplate) RenderTerraform(target *terraform.TerraformTarget, a, e
328
313
329
314
return target .RenderResource ("aws_launch_template" , fi .ValueOf (e .Name ), tf )
330
315
}
316
+
317
+ func createTerraformLaunchTemplateBlockDevice (deviceName string , v * BlockDeviceMapping ) * terraformLaunchTemplateBlockDevice {
318
+ return & terraformLaunchTemplateBlockDevice {
319
+ DeviceName : fi .PtrTo (deviceName ),
320
+ EBS : []* terraformLaunchTemplateBlockDeviceEBS {
321
+ {
322
+ DeleteOnTermination : fi .PtrTo (true ),
323
+ Encrypted : v .EbsEncrypted ,
324
+ KmsKeyID : v .EbsKmsKey ,
325
+ IOPS : v .EbsVolumeIops ,
326
+ Throughput : v .EbsVolumeThroughput ,
327
+ VolumeSize : v .EbsVolumeSize ,
328
+ VolumeType : fi .PtrTo (string (v .EbsVolumeType )),
329
+ },
330
+ },
331
+ }
332
+ }
0 commit comments