Refactor LaunchTemplate.SSHKey

This commit is contained in:
John Gardiner Myers 2021-05-11 14:05:25 -07:00
parent b0bcf40921
commit 4d9018282c
1 changed files with 6 additions and 7 deletions

View File

@ -184,7 +184,6 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde
RootVolumeType: fi.String(rootVolumeType), RootVolumeType: fi.String(rootVolumeType),
RootVolumeEncryption: fi.Bool(rootVolumeEncryption), RootVolumeEncryption: fi.Bool(rootVolumeEncryption),
RootVolumeKmsKey: fi.String(rootVolumeKmsKey), RootVolumeKmsKey: fi.String(rootVolumeKmsKey),
SSHKey: lc.SSHKey,
SecurityGroups: lc.SecurityGroups, SecurityGroups: lc.SecurityGroups,
Tags: tags, Tags: tags,
Tenancy: lc.Tenancy, Tenancy: lc.Tenancy,
@ -275,6 +274,12 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde
lt.RootVolumeIops = nil 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 // When using a MixedInstances ASG, AWS requires the SpotPrice be defined on the ASG
// rather than the LaunchTemplate or else it returns this error: // rather than the LaunchTemplate or else it returns this error:
// You cannot use a launch template that is set to request Spot Instances (InstanceMarketOptions) // 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) 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 // @step: add the instancegroup userdata
if t.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig); err != nil { if t.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig); err != nil {
return nil, err return nil, err