kubernetes/kops · error

error parsing target group ARN: %v

Error message

error parsing target group ARN: %v

What it means

NameForExternalTargetGroup derives a target group name from an ELBV2 target group ARN. It first calls arn.Parse on the supplied ARN; if the string is not a valid AWS ARN it returns this wrapped error. It is thrown only for malformed/unparseable ARN strings, before resource-part validation happens.

Source

Thrown at upup/pkg/fi/cloudup/awsup/aws_utils.go:254

// GetResourceName32 will attempt to calculate a meaningful name for a resource given a prefix
// Will never return a string longer than 32 chars
func GetResourceName32(cluster string, prefix string) string {
	s := prefix + "-" + strings.ReplaceAll(cluster, ".", "-")

	// We always compute the hash and add it, lest we trick users into assuming that we never do this
	opt := truncate.TruncateStringOptions{
		MaxLength:     32,
		AlwaysAddHash: true,
		HashLength:    6,
	}
	return truncate.TruncateString(s, opt)
}

// NameForExternalTargetGroup will attempt to calculate a meaningful name for a target group given an ARN.
func NameForExternalTargetGroup(targetGroupARN string) (string, error) {
	parsed, err := arn.Parse(targetGroupARN)
	if err != nil {
		return "", fmt.Errorf("error parsing target group ARN: %v", err)
	}
	resource := strings.Split(parsed.Resource, "/")
	if len(resource) != 3 || resource[0] != "targetgroup" {
		return "", fmt.Errorf("error parsing target group ARN resource: %q", parsed.Resource)
	}
	return resource[1], nil
}

func IsIAMNoSuchEntityException(err error) bool {
	if err == nil {
		return false
	}
	var nse *iamtypes.NoSuchEntityException
	return errors.As(err, &nse)
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the targetGroupARN string is a complete ARN of the form arn:aws:elasticloadbalancing:<region>:<account>:targetgroup/<name>/<id>.
  2. Copy the ARN directly from `aws elbv2 describe-target-groups --query 'TargetGroups[*].TargetGroupArn'` instead of hand-typing it.
  3. Check the cluster spec / config source feeding the ARN for empty or truncated values before calling the function.

Example fix

// before
name, err := NameForExternalTargetGroup("my-target-group")
// after
name, err := NameForExternalTargetGroup("arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-target-group/abc123")
Defensive patterns

Strategy: validation

Validate before calling

if !strings.HasPrefix(arn, "arn:") { return fmt.Errorf("not an ARN: %q", arn) }
parsed, err := arn.Parse(arn); if err != nil { return err }

Type guard

func isTargetGroupARN(s string) bool {
	p, err := arn.Parse(s)
	if err != nil { return false }
	r := strings.Split(p.Resource, "/")
	return len(r) == 3 && r[0] == "targetgroup"
}

Try / catch

name, err := NameForExternalTargetGroup(tgARN)
if err != nil {
	return fmt.Errorf("invalid target group ARN %q: %w", tgARN, err)
}

Prevention

When it happens

Trigger: Calling NameForExternalTargetGroup with an empty string, a target group name instead of a full ARN, a typo-truncated ARN, or any string not matching arn:partition:service:region:account-id:resource syntax.

Common situations: Users paste the target group name or URL from the AWS console instead of the ARN; config values read from env vars/cluster spec are empty or stale; copying an ARN from another partition or a legacy ELB (classic) whose ARN format differs.

Related errors


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