{"record":{"id":"f6f99f7ed6f467cf","repo":"kubernetes/kops","slug":"error-deleting-detached-instances-for-autoscaling","errorCode":null,"errorMessage":"error deleting detached instances for autoscaling group %q: %v","messagePattern":"error deleting detached instances for autoscaling group %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_cloud.go","lineNumber":409,"sourceCode":"\ttemplate := aws.ToString(asg.LaunchConfigurationName)\n\tlaunchTemplate := \"\"\n\tif asg.LaunchTemplate != nil {\n\t\tlaunchTemplate = aws.ToString(asg.LaunchTemplate.LaunchTemplateName)\n\t}\n\n\t// Delete detached instances\n\t{\n\t\tdetached, err := findDetachedInstances(ctx, c, asg)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error searching for detached instances for autoscaling group %q: %v\", name, err)\n\t\t}\n\t\tif len(detached) > 0 {\n\t\t\tklog.V(2).Infof(\"Deleting detached instances for autoscaling group %q\", name)\n\t\t\treq := &ec2.TerminateInstancesInput{\n\t\t\t\tInstanceIds: detached,\n\t\t\t}\n\t\t\tif _, err := c.EC2().TerminateInstances(ctx, req); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error deleting detached instances for autoscaling group %q: %v\", name, err)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Delete ASG\n\t{\n\t\tklog.V(2).Infof(\"Deleting autoscaling group %q\", name)\n\t\trequest := &autoscaling.DeleteAutoScalingGroupInput{\n\t\t\tAutoScalingGroupName: aws.String(name),\n\t\t\tForceDelete:          aws.Bool(true),\n\t\t}\n\t\t_, err := c.Autoscaling().DeleteAutoScalingGroup(ctx, request)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting autoscaling group %q: %v\", name, err)\n\t\t}\n\t}\n\n\t// Delete LaunchConfig","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L391-L427","documentation":"TerminateInstances failed while terminating the instances previously detached from the autoscaling group during cluster/IG teardown; the wrapped error is the AWS EC2 API response.","triggerScenarios":"Thrown at upup/pkg/fi/cloudup/awsup/aws_cloud.go:409 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the instances still exist and ec2:TerminateInstances permission is granted","Retry the delete; instances may have been terminated concurrently"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}