{"record":{"id":"046b8066057fe32d","repo":"kubernetes/kops","slug":"failed-to-detach-target-groups-from-autoscaling-gr","errorCode":null,"errorMessage":"failed to detach target groups from autoscaling group: %v","messagePattern":"failed to detach target groups from autoscaling group: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go","lineNumber":1094,"sourceCode":"\td.autoScalingGroupName = autoScalingGroupName\n\td.targetGroupARN = targetGroupARN\n\treturn d\n}\n\nfunc (d *deleteAutoscalingTargetGroupAttachment) Delete(t fi.CloudupTarget) error {\n\tctx := context.TODO()\n\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\treq := &autoscaling.DetachLoadBalancerTargetGroupsInput{\n\t\tAutoScalingGroupName: aws.String(d.autoScalingGroupName),\n\t\tTargetGroupARNs:      []string{d.targetGroupARN},\n\t}\n\tif _, err := awsTarget.Cloud.Autoscaling().DetachLoadBalancerTargetGroups(ctx, req); err != nil {\n\t\treturn fmt.Errorf(\"failed to detach target groups from autoscaling group: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (d *deleteAutoscalingTargetGroupAttachment) TaskName() string {\n\treturn \"autoscaling-elb-attachment\"\n\n}\nfunc (d *deleteAutoscalingTargetGroupAttachment) Item() string {\n\treturn d.autoScalingGroupName + \":\" + d.targetGroupARN\n}\n\nfunc (d *deleteAutoscalingTargetGroupAttachment) DeferDeletion() bool {\n\treturn true\n}\n","sourceCodeStart":1076,"sourceCodeEnd":1111,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go#L1076-L1111","documentation":"A deferred cloud-deletion task failed to detach a target group from the autoscaling group (DetachLoadBalancerTargetGroups); the target group may remain attached after the apply, and the wrapped error is the AWS ELBV2/ASG API response.","triggerScenarios":"deleteAutoscalingTargetGroupAttachment.Delete builds DetachLoadBalancerTargetGroupsInput with the ASG name and target group ARN and the AWS call fails: ASG not found (already deleted), target group not attached or ARN no longer exists, throttling, or missing autoscaling:DetachLoadBalancerTargetGroups permission.","commonSituations":"kops delete cluster where the ASG was already removed out-of-band; NLB/target group deleted first so detach is invalid; permission revoked; throttling during parallel teardown.","solutions":["If the wrapped error says the ASG or target group does not exist, the resource is already gone — re-run the delete/refresh state to clear the stale task.","Verify IAM permissions include autoscaling:DetachLoadBalancerTargetGroups.","Retry after backoff if throttled; deletion flows often race on AWS rate limits.","Detach manually via `aws autoscaling detach-load-balancer-target-groups` if kops state is wedged, then re-run kops delete."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify ASG and target group still exist before detaching\nif _, err := svc.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{AutoScalingGroupNames: []string{asgName}}); err != nil {\n  return nil // ASG already gone; nothing to detach\n}\n_, err := elbv2Svc.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{TargetGroupArns: []string{arn}})","typeGuard":null,"tryCatchPattern":"if _, err := svc.DetachLoadBalancerTargetGroups(ctx, req); err != nil {\n  if isNotFound(err) {\n    klog.V(2).Infof(\"ASG/target group already removed; treating delete as done\")\n    return nil\n  }\n  if isThrottle(err) {\n    return retryWithBackoff(req)\n  }\n  return fmt.Errorf(\"failed to detach target groups from autoscaling group: %v\", err)\n}","preventionTips":["Let kops delete clusters end-to-end; avoid deleting ASGs or NLBs out-of-band mid-teardown.","Grant autoscaling:DetachLoadBalancerTargetGroups to kops credentials.","Retry deletes with backoff; teardown is throttle-prone."],"tags":["aws","autoscaling","target-group","deletion"],"backgroundTag":"aws-api-call-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}