{"record":{"id":"ebd033240fabfb13","repo":"hashicorp/nomad","slug":"invalid-name-q-must-match-regex-s","errorCode":null,"errorMessage":"invalid name %q, must match regex %s","messagePattern":"invalid name %q, must match regex (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/consul.go","lineNumber":100,"sourceCode":"\tvar clusterName string\n\tif c != nil && c.Cluster != \"\" {\n\t\tclusterName = c.Cluster\n\t} else {\n\t\tclusterName = ConsulDefaultCluster\n\t}\n\n\treturn fmt.Sprintf(\"%s_%s\", ConsulTaskIdentityNamePrefix, clusterName)\n}\n\nvar (\n\t// validConsulVaultClusterName is the rule used to validate a Consul or\n\t// Vault cluster name.\n\tvalidConsulVaultClusterName = regexp.MustCompile(\"^[a-zA-Z0-9-_]{1,128}$\")\n)\n\nfunc ValidateConsulClusterName(cluster string) error {\n\tif !validConsulVaultClusterName.MatchString(cluster) {\n\t\treturn fmt.Errorf(\"invalid name %q, must match regex %s\", cluster, validConsulVaultClusterName)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":82,"sourceCodeEnd":105,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/consul.go#L82-L105","documentation":"ValidateConsulClusterName validates Consul (and Vault) cluster names against ^[a-zA-Z0-9-_]{1,128}$. If the name contains other characters (dots, slashes, spaces, colons) or exceeds 128 characters, this error is returned. Cluster names must be simple identifiers so they can be safely used in configuration and state references.","triggerScenarios":"Configuring a Consul cluster (e.g. nomad consul blocks or agent config 'consul.cluster') with a name containing invalid characters like '.' or ':' or longer than 128 chars, via IsValidConfig during config validation.","commonSituations":"Naming clusters after FQDNs ('consul.prod.example.com'); including URL schemes or paths; pasting an address instead of a name into the cluster name field.","solutions":["Rename the cluster using only letters, digits, hyphens, and underscores (1-128 chars), e.g. \"dc1-prod\".","Move DNS names/addresses into the address field, not the cluster name.","Validate with the regex ^[a-zA-Z0-9-_]{1,128}$ before deploying config."],"exampleFix":"// before\nconsul {\n  name = \"consul.prod.example.com\"\n}\n// after\nconsul {\n  name = \"consul-prod\"\n  address = \"consul.prod.example.com:8500\"\n}","handlingStrategy":"validation","validationCode":"var clusterNameRe = regexp.MustCompile(`^[a-zA-Z0-9-_]{1,128}$`)\nif !clusterNameRe.MatchString(clusterName) {\n  return fmt.Errorf(\"cluster name %q must match [a-zA-Z0-9-_]{1,128}\", clusterName)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use simple identifier-style names (letters, digits, '-', '_') for clusters.","Keep addresses/DNS names in address fields, not name fields.","Add the regex to config linting pipelines."],"tags":["nomad","consul","config-validation","naming"],"backgroundTag":"invalid-name-regex","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}