From 4d9018282ccbbcd231e6ded313a2a7fcb44e3261 Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Tue, 11 May 2021 14:05:25 -0700 Subject: [PATCH] Refactor LaunchTemplate.SSHKey --- pkg/model/awsmodel/autoscalinggroup.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/model/awsmodel/autoscalinggroup.go b/pkg/model/awsmodel/autoscalinggroup.go index d705a2be53..7bc626bcd6 100644 --- a/pkg/model/awsmodel/autoscalinggroup.go +++ b/pkg/model/awsmodel/autoscalinggroup.go @@ -184,7 +184,6 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde RootVolumeType: fi.String(rootVolumeType), RootVolumeEncryption: fi.Bool(rootVolumeEncryption), RootVolumeKmsKey: fi.String(rootVolumeKmsKey), - SSHKey: lc.SSHKey, SecurityGroups: lc.SecurityGroups, Tags: tags, Tenancy: lc.Tenancy, @@ -275,6 +274,12 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde lt.RootVolumeIops = nil } + if b.AWSModelContext.UseSSHKey() { + if lt.SSHKey, err = b.LinkToSSHKey(); err != nil { + return nil, err + } + } + // When using a MixedInstances ASG, AWS requires the SpotPrice be defined on the ASG // rather than the LaunchTemplate or else it returns this error: // You cannot use a launch template that is set to request Spot Instances (InstanceMarketOptions) @@ -346,12 +351,6 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateHelper(c *fi.ModelBuil t.SecurityGroups = append(t.SecurityGroups, sgTask) } - if b.AWSModelContext.UseSSHKey() { - if t.SSHKey, err = b.LinkToSSHKey(); err != nil { - return nil, err - } - } - // @step: add the instancegroup userdata if t.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig); err != nil { return nil, err