{"record":{"id":"8fd72d7ac59842a3","repo":"kubernetes/kops","slug":"error-deleting-launchtemplate-s-error-s","errorCode":null,"errorMessage":"error deleting LaunchTemplate %s: error: %s","messagePattern":"error deleting LaunchTemplate (.+?): error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go","lineNumber":441,"sourceCode":"\treturn \"LaunchTemplate\"\n}\n\n// Item returns the launch template name\nfunc (d *deleteLaunchTemplate) Item() string {\n\treturn fi.ValueOf(d.lc.LaunchTemplateName)\n}\n\nfunc (d *deleteLaunchTemplate) Delete(t fi.CloudupTarget) error {\n\tctx := context.TODO()\n\tawsTarget, ok := t.(*awsup.AWSAPITarget)\n\tif !ok {\n\t\treturn fmt.Errorf(\"unexpected target type for deletion: %T\", t)\n\t}\n\n\tif _, err := awsTarget.Cloud.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{\n\t\tLaunchTemplateName: d.lc.LaunchTemplateName,\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"error deleting LaunchTemplate %s: error: %s\", d.Item(), err)\n\t}\n\n\treturn nil\n}\n\n// String returns a string representation of the task\nfunc (d *deleteLaunchTemplate) String() string {\n\treturn d.TaskName() + \"-\" + d.Item()\n}\n\nfunc (d *deleteLaunchTemplate) DeferDeletion() bool {\n\treturn false // TODO: Should we defer deletion?\n}\n","sourceCodeStart":423,"sourceCodeEnd":455,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go#L423-L455","documentation":"Wraps an error returned by ec2:DeleteLaunchTemplate when deleteLaunchTemplate.Delete removes an orphaned launch template. The template could not be deleted, so FindDeletions cleanup fails and the error is surfaced with the task name and underlying message.","triggerScenarios":"DeleteLaunchTemplate fails: launch template in use by an Auto Scaling Group, AccessDenied on ec2:DeleteLaunchTemplates, template already deleted, throttling, or invalid launch template name/ID.","commonSituations":"Orphaned template still referenced by an ASG created outside kOps or by a scaled node group; IAM role missing delete permission; concurrent kOps runs deleting the same template.","solutions":["Read the wrapped error: 'InvalidLaunchTemplateId.InUse' means detach/delete the referencing ASG first","Confirm no Auto Scaling Groups reference the template (aws autoscaling describe-auto-scaling-groups)","Grant ec2:DeleteLaunchTemplates to the kOps IAM role","Re-run kops update if the template was already deleted (error will be NotFound — safe to ignore/retry)","Retry after throttling backoff"],"exampleFix":"// before\naws autoscaling create-auto-scaling-group --launch-template LaunchTemplateName=my-template\n// after\naws autoscaling update-auto-scaling-group --auto-scaling-group-name my-asg --launch-template LaunchTemplateName=new-template\n# then re-run: kops update cluster","handlingStrategy":"retry","validationCode":"out, err := cloud.EC2().DescribeLaunchTemplates(ctx, &ec2.DescribeLaunchTemplatesInput{\n  LaunchTemplateNames: []string{*d.lc.LaunchTemplateName},\n})\nif err != nil || len(out.LaunchTemplates) == 0 { return nil } // nothing to delete\n// also check referencing ASGs before deleting","typeGuard":null,"tryCatchPattern":"if _, err := ec2().DeleteLaunchTemplate(ctx, input); err != nil {\n  var awsErr smithy.APIError\n  if errors.As(err, &awsErr) && strings.Contains(awsErr.ErrorCode(), \"NotFound\") {\n    return nil // already deleted\n  }\n  return fmt.Errorf(\"error deleting LaunchTemplate: %w\", err)\n}","preventionTips":["Check ASG references before deleting a launch template","Treat NotFound as success (idempotent delete)","Grant ec2:DeleteLaunchTemplates in IAM","Avoid concurrent kOps runs against the same cluster"],"tags":["aws","ec2","launch-template","deletion"],"backgroundTag":"resource-in-use","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}