{"record":{"id":"ec22497f748bafb2","repo":"kubernetes/kops","slug":"failed-to-attach-target-groups-v","errorCode":null,"errorMessage":"failed to attach target groups: %v","messagePattern":"failed to attach target groups: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go","lineNumber":688,"sourceCode":"\t\t\tif _, err := t.Cloud.Autoscaling().CreateOrUpdateTags(ctx, updateTagsRequest); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error updating AutoscalingGroup tags: %v\", err)\n\t\t\t}\n\t\t}\n\n\t\tif detachLBRequest != nil {\n\t\t\tif _, err := t.Cloud.Autoscaling().DetachLoadBalancers(ctx, detachLBRequest); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error detatching LoadBalancers: %v\", err)\n\t\t\t}\n\t\t}\n\t\tif attachLBRequest != nil {\n\t\t\tif _, err := t.Cloud.Autoscaling().AttachLoadBalancers(ctx, attachLBRequest); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error attaching LoadBalancers: %v\", err)\n\t\t\t}\n\t\t}\n\t\tif len(attachTGRequests) > 0 {\n\t\t\tfor _, attachTGRequest := range attachTGRequests {\n\t\t\t\tif _, err := t.Cloud.Autoscaling().AttachLoadBalancerTargetGroups(ctx, attachTGRequest); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to attach target groups: %v\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// UseMixedInstancesPolicy checks if we should add a mixed instances policy to the asg\nfunc (e *AutoscalingGroup) UseMixedInstancesPolicy() bool {\n\tif e.LaunchTemplate == nil {\n\t\treturn false\n\t}\n\t// @check if any of the mixed instance policies settings are toggled\n\tif e.MixedOnDemandAboveBase != nil {\n\t\treturn true\n\t}\n\tif e.MixedOnDemandBase != nil {","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go#L670-L706","documentation":"kops wraps the AWS AutoScaling AttachLoadBalancerTargetGroups API error when attaching target groups (NLB/ALB) to an AutoScalingGroup in RenderAWS. AWS rejected one of the per-target-group attach calls.","triggerScenarios":"During ASG update with len(attachTGRequests) > 0, Autoscaling().AttachLoadBalancerTargetGroups fails: target group ARN invalid/deleted, target group in different VPC than ASG subnets, throttling, or missing autoscaling:AttachLoadBalancerTargetGroups permission.","commonSituations":"NLB was deleted and recreated so its target group ARN changed while kops cached the old one; loadBalancer attachment referencing a target group from another VPC; permissions tightened by SCP.","solutions":["Re-run `kops update cluster --yes` or `kops toolbox dump` to refresh target group ARNs; if the NLB was recreated, re-export or re-apply so the ARN updates.","Verify the target group VPC matches the ASG subnets VPC.","Confirm IAM allows autoscaling:AttachLoadBalancerTargetGroups and elasticloadbalancing:DescribeTargetGroups.","Retry after backoff if throttled."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify target group ARN exists and VPC matches\nout, err := elbv2Svc.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{TargetGroupArns: []string{arn}})\nif err != nil { return fmt.Errorf(\"target group %s not found: %w\", arn, err) }\nif *out.TargetGroups[0].VpcId != asgVpcID { return errors.New(\"target group VPC mismatch\") }","typeGuard":null,"tryCatchPattern":"if _, err := svc.AttachLoadBalancerTargetGroups(ctx, req); err != nil {\n  if isNotFound(err) {\n    return fmt.Errorf(\"stale target group ARN - re-run kops update cluster: %w\", err)\n  }\n  return retry(err)\n}","preventionTips":["Don't delete/recreate NLBs out-of-band; ARNs change.","Keep target groups in the same VPC as cluster subnets.","Refresh kops state after any manual load balancer changes."],"tags":["aws","autoscaling","target-group","cloud-api"],"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-12T07:17:12.445Z"}