{"record":{"id":"7522ff72e93e4884","repo":"kubernetes/kops","slug":"error-deleting-ec2-launchtemplate-q-v","errorCode":null,"errorMessage":"error deleting ec2 LaunchTemplate %q: %v","messagePattern":"error deleting ec2 LaunchTemplate %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":1445,"sourceCode":"\t\t}\n\t}\n\n\treturn resourceTrackers, nil\n}\n\n// DeleteAutoScalingGroupLaunchTemplate deletes\nfunc DeleteAutoScalingGroupLaunchTemplate(cloud fi.Cloud, r *resources.Resource) error {\n\tctx := context.TODO()\n\tc, ok := cloud.(awsup.AWSCloud)\n\tif !ok {\n\t\treturn errors.New(\"expected a aws.Cloud provider\")\n\t}\n\tklog.V(2).Infof(\"Deleting EC2 LaunchTemplate %q\", r.ID)\n\n\tif _, err := c.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{\n\t\tLaunchTemplateId: new(r.ID),\n\t}); err != nil {\n\t\treturn fmt.Errorf(\"error deleting ec2 LaunchTemplate %q: %v\", r.ID, err)\n\t}\n\n\treturn nil\n}\n\nfunc DeleteELB(cloud fi.Cloud, r *resources.Resource) error {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tid := r.ID\n\n\tklog.V(2).Infof(\"Deleting ELB %q\", id)\n\trequest := &elb.DeleteLoadBalancerInput{\n\t\tLoadBalancerName: &id,\n\t}\n\t_, err := c.ELB().DeleteLoadBalancer(ctx, request)\n\tif err != nil {\n\t\tif IsDependencyViolation(err) {","sourceCodeStart":1427,"sourceCodeEnd":1463,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L1427-L1463","documentation":"Thrown when EC2 DeleteLaunchTemplate fails while deleting the launch template backing an AutoScaling group during cluster teardown. The template ID and underlying AWS error are embedded in the message.","triggerScenarios":"DeleteLaunchTemplate returns InvalidLaunchTemplateId.NotFound (already deleted), DependencyViolation (still in use by an ASG/version in use), or UnauthorizedOperation.","commonSituations":"ASG deletion hasn't fully propagated so the template still has dependent resources (dependency race during teardown); template removed by a previous run; IAM missing ec2:DeleteLaunchTemplate.","solutions":["If the code is InvalidLaunchTemplateId.NotFound, it is already deleted — re-run kops delete cluster.","For DependencyViolation, wait for ASG deletion to finish, then retry.","Fix IAM (ec2:DeleteLaunchTemplate) if UnauthorizedOperation.","Check the template: `aws ec2 describe-launch-templates --launch-template-ids <id>`."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"out, err := ec2Client.DescribeLaunchTemplates(ctx, &ec2.DescribeLaunchTemplatesInput{LaunchTemplateIds: []string{id}}); if err != nil || len(out.LaunchTemplates) == 0 { /* already deleted, skip */ }","typeGuard":"func isLaunchTemplateNotFound(err error) bool { return awsup.AWSErrorCode(err) == \"InvalidLaunchTemplateId.NotFound\" }","tryCatchPattern":"err := DeleteAutoScalingGroupLaunchTemplate(cloud, r)\nif err != nil {\n\tif isLaunchTemplateNotFound(err) { return nil } // already deleted\n\tif awsup.AWSErrorCode(err) == \"DependencyViolation\" { return err } // retry after ASG is gone\n\treturn err\n}","preventionTips":["Delete ASGs before their launch templates (kops ordering does this — don't skip steps)","Handle InvalidLaunchTemplateId.NotFound as success for idempotency","Retry on DependencyViolation after a short delay"],"tags":["aws","ec2","launch-template","deletion","api-error"],"backgroundTag":"aws-dependency-violation","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"}