diff --git a/pkg/model/awsmodel/autoscalinggroup.go b/pkg/model/awsmodel/autoscalinggroup.go index 2bc52602c7..7eb2f9c81b 100644 --- a/pkg/model/awsmodel/autoscalinggroup.go +++ b/pkg/model/awsmodel/autoscalinggroup.go @@ -143,7 +143,6 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde lt := &awstasks.LaunchTemplate{ Name: fi.String(name), Lifecycle: b.Lifecycle, - AssociatePublicIP: lc.AssociatePublicIP, BlockDeviceMappings: lc.BlockDeviceMappings, IAMInstanceProfile: lc.IAMInstanceProfile, ImageID: lc.ImageID, @@ -162,6 +161,26 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateTask(c *fi.ModelBuilde HTTPTokens: lc.HTTPTokens, HTTPPutResponseHopLimit: lc.HTTPPutResponseHopLimit, } + + { + // @step: check the subnets are ok and pull together an array for us + subnets, err := b.GatherSubnets(ig) + if err != nil { + return nil, err + } + + // @step: check if we can add an public ip to this subnet + switch subnets[0].Type { + case kops.SubnetTypePublic, kops.SubnetTypeUtility: + lt.AssociatePublicIP = fi.Bool(true) + if ig.Spec.AssociatePublicIP != nil { + lt.AssociatePublicIP = ig.Spec.AssociatePublicIP + } + case kops.SubnetTypePrivate: + lt.AssociatePublicIP = fi.Bool(false) + } + } + // 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) @@ -361,23 +380,6 @@ func (b *AutoscalingGroupModelBuilder) buildLaunchTemplateHelper(c *fi.ModelBuil return nil, err } - // @step: check the subnets are ok and pull together an array for us - subnets, err := b.GatherSubnets(ig) - if err != nil { - return nil, err - } - - // @step: check if we can add an public ip to this subnet - switch subnets[0].Type { - case kops.SubnetTypePublic, kops.SubnetTypeUtility: - t.AssociatePublicIP = fi.Bool(true) - if ig.Spec.AssociatePublicIP != nil { - t.AssociatePublicIP = ig.Spec.AssociatePublicIP - } - case kops.SubnetTypePrivate: - t.AssociatePublicIP = fi.Bool(false) - } - return t, nil } diff --git a/upup/pkg/fi/cloudup/awstasks/launchtemplate.go b/upup/pkg/fi/cloudup/awstasks/launchtemplate.go index 87c85e7764..b8058e1bc3 100644 --- a/upup/pkg/fi/cloudup/awstasks/launchtemplate.go +++ b/upup/pkg/fi/cloudup/awstasks/launchtemplate.go @@ -35,7 +35,7 @@ type LaunchTemplate struct { // Lifecycle is the resource lifecycle Lifecycle *fi.Lifecycle - // AssociatePublicIP indicates if a public ip address is assigned to instabces + // AssociatePublicIP indicates if a public ip address is assigned to instances AssociatePublicIP *bool // BlockDeviceMappings is a block device mappings BlockDeviceMappings []*BlockDeviceMapping