kubernetes/kops · error

error deleting ec2 LaunchTemplate %q: %v

Error message

error deleting ec2 LaunchTemplate %q: %v

What it means

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.

Source

Thrown at pkg/resources/aws/aws.go:1445

		}
	}

	return resourceTrackers, nil
}

// DeleteAutoScalingGroupLaunchTemplate deletes
func DeleteAutoScalingGroupLaunchTemplate(cloud fi.Cloud, r *resources.Resource) error {
	ctx := context.TODO()
	c, ok := cloud.(awsup.AWSCloud)
	if !ok {
		return errors.New("expected a aws.Cloud provider")
	}
	klog.V(2).Infof("Deleting EC2 LaunchTemplate %q", r.ID)

	if _, err := c.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{
		LaunchTemplateId: new(r.ID),
	}); err != nil {
		return fmt.Errorf("error deleting ec2 LaunchTemplate %q: %v", r.ID, err)
	}

	return nil
}

func DeleteELB(cloud fi.Cloud, r *resources.Resource) error {
	ctx := context.TODO()
	c := cloud.(awsup.AWSCloud)

	id := r.ID

	klog.V(2).Infof("Deleting ELB %q", id)
	request := &elb.DeleteLoadBalancerInput{
		LoadBalancerName: &id,
	}
	_, err := c.ELB().DeleteLoadBalancer(ctx, request)
	if err != nil {
		if IsDependencyViolation(err) {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. If the code is InvalidLaunchTemplateId.NotFound, it is already deleted — re-run kops delete cluster.
  2. For DependencyViolation, wait for ASG deletion to finish, then retry.
  3. Fix IAM (ec2:DeleteLaunchTemplate) if UnauthorizedOperation.
  4. Check the template: `aws ec2 describe-launch-templates --launch-template-ids <id>`.
Defensive patterns

Strategy: type-guard

Validate before calling

out, err := ec2Client.DescribeLaunchTemplates(ctx, &ec2.DescribeLaunchTemplatesInput{LaunchTemplateIds: []string{id}}); if err != nil || len(out.LaunchTemplates) == 0 { /* already deleted, skip */ }

Type guard

func isLaunchTemplateNotFound(err error) bool { return awsup.AWSErrorCode(err) == "InvalidLaunchTemplateId.NotFound" }

Try / catch

err := DeleteAutoScalingGroupLaunchTemplate(cloud, r)
if err != nil {
	if isLaunchTemplateNotFound(err) { return nil } // already deleted
	if awsup.AWSErrorCode(err) == "DependencyViolation" { return err } // retry after ASG is gone
	return err
}

Prevention

When it happens

Trigger: DeleteLaunchTemplate returns InvalidLaunchTemplateId.NotFound (already deleted), DependencyViolation (still in use by an ASG/version in use), or UnauthorizedOperation.

Common situations: 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.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/7522ff72e93e4884. Report an issue: GitHub.