{"record":{"id":"542ed71a5b949594","repo":"kubernetes/kops","slug":"error-deleting-targetgroup-q-v","errorCode":null,"errorMessage":"error deleting TargetGroup %q: %v","messagePattern":"error deleting TargetGroup %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":1504,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc DeleteTargetGroup(cloud fi.Cloud, r *resources.Resource) error {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\tid := r.ID\n\n\tklog.V(2).Infof(\"Deleting TargetGroup %q\", id)\n\trequest := &elbv2.DeleteTargetGroupInput{\n\t\tTargetGroupArn: aws.String(id),\n\t}\n\t_, err := c.ELBV2().DeleteTargetGroup(ctx, request)\n\tif err != nil {\n\t\tif IsDependencyViolation(err) {\n\t\t\treturn err\n\t\t}\n\t\treturn fmt.Errorf(\"error deleting TargetGroup %q: %v\", id, err)\n\t}\n\treturn nil\n}\n\nfunc DumpELB(op *resources.DumpOperation, r *resources.Resource) error {\n\tdata := make(map[string]interface{})\n\tdata[\"id\"] = r.ID\n\tdata[\"type\"] = TypeLoadBalancer\n\tdata[\"raw\"] = r.Obj\n\top.Dump.Resources = append(op.Dump.Resources, data)\n\n\tif lb, ok := r.Obj.(elbv2types.LoadBalancer); ok {\n\t\top.Dump.LoadBalancers = append(op.Dump.LoadBalancers, &resources.LoadBalancer{\n\t\t\tName:    fi.ValueOf(lb.LoadBalancerName),\n\t\t\tDNSName: fi.ValueOf(lb.DNSName),\n\t\t})\n\n\t}","sourceCodeStart":1486,"sourceCodeEnd":1522,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L1486-L1522","documentation":"DeleteTargetGroup wraps a failed ELBV2 DeleteTargetGroup API call with the target group ARN. As with the sibling deleters, dependency violations are returned unwrapped so the resource tracker can retry after dependents are removed.","triggerScenarios":"DeleteTargetGroup fails because the target group is still referenced by a listener (TargetGroupInUse), is still associated with an ALB/NLB being deleted concurrently, IAM denies elasticloadbalancing:DeleteTargetGroup, or throttling occurs.","commonSituations":"Cluster teardown order where the ALB deletion hasn't completed before target group deletion; leftover listeners still pointing at the TG; API throttling across many resources.","solutions":["Ensure the ALB/NLB listeners referencing the target group are deleted first, then retry — order matters and the tracker retries dependency violations.","Retry the teardown after a short wait; ELB deletion is asynchronous.","Verify IAM permissions include elasticloadbalancing:DeleteTargetGroup.","Check with aws elbv2 describe-target-groups whether the TG still exists; if gone, continue.","Reduce API concurrency if throttling errors appear in the wrapped message."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure no listeners still reference the target group\nlbs, _ := c.ELBV2().DescribeLoadBalancers(ctx, &elbv2.DescribeLoadBalancersInput{})\nfor _, lb := range lbs.LoadBalancers {\n    ls, _ := c.ELBV2().DescribeListeners(ctx, &elbv2.DescribeListenersInput{LoadBalancerArn: lb.LoadBalancerArn})\n    for _, l := range ls.Listeners {\n        for _, tg := range l.DefaultActions { if *tg.TargetGroupArn == arn { /* delete listener first */ } }\n    }\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 5; attempt++ {\n    err := DeleteTargetGroup(cloud, r)\n    if err == nil || awsup.AWSErrorCode(err) == \"TargetGroupInUse\" && attempt < 4 {\n        time.Sleep(time.Duration(1<<attempt) * time.Second); continue\n    }\n    return err\n}","preventionTips":["Always delete listeners before target groups.","Retry on TargetGroupInUse; ALB deletion is asynchronous.","Grant elasticloadbalancing:DeleteTargetGroup in IAM.","Verify TG ARN/region correctness.","Batch teardowns with pacing to avoid throttling."],"tags":["aws","elbv2","target-group","deletion"],"backgroundTag":"aws-api-delete-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"}