{"record":{"id":"d2ae3b45345169b3","repo":"hashicorp/terraform","slug":"failed-to-create-backend-alias-from-alias-q-the","errorCode":null,"errorMessage":"failed to create backend alias from alias %q. The hostname is not in the correct format. This is a bug in the backend","messagePattern":"failed to create backend alias from alias %q\\. The hostname is not in the correct format\\. This is a bug in the backend","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/backend/remote/backend.go","lineNumber":210,"sourceCode":"\n\t// Make sure that only one of workspace name or a prefix is configured.\n\tif name != \"\" && prefix != \"\" {\n\t\tdiags = diags.Append(tfdiags.AttributeValue(\n\t\t\ttfdiags.Error,\n\t\t\t\"Invalid workspaces configuration\",\n\t\t\t`Only one of workspace \"name\" or \"prefix\" is allowed.`,\n\t\t\tcty.Path{cty.GetAttrStep{Name: \"workspaces\"}},\n\t\t))\n\t}\n\n\treturn obj, diags\n}\n\nfunc (b *Remote) ServiceDiscoveryAliases() ([]backendrun.HostAlias, error) {\n\taliasHostname, err := svchost.ForComparison(genericHostname)\n\tif err != nil {\n\t\t// This should never happen because the hostname is statically defined.\n\t\treturn nil, fmt.Errorf(\"failed to create backend alias from alias %q. The hostname is not in the correct format. This is a bug in the backend\", genericHostname)\n\t}\n\n\ttargetHostname, err := svchost.ForComparison(b.hostname)\n\tif err != nil {\n\t\t// This should never happen because the 'to' alias is the backend host, which has likely\n\t\t// already been evaluated as a svchost.Hostname by now\n\t\treturn nil, fmt.Errorf(\"failed to create backend alias to target %q. The hostname is not in the correct format\", b.hostname)\n\t}\n\n\treturn []backendrun.HostAlias{\n\t\t{\n\t\t\tFrom: aliasHostname,\n\t\t\tTo:   targetHostname,\n\t\t},\n\t}, nil\n}\n\n// Configure implements backend.Backend.","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote/backend.go#L192-L228","documentation":"Thrown by the Terraform Cloud/Enterprise remote backend's ServiceDiscoveryAliases when svchost.ForComparison rejects the statically-defined genericHostname constant (\"localterraform.com\"). The code comment is explicit: this should never happen because the hostname is a compile-time constant. Reaching this error indicates the constant itself is malformed — i.e. a bug shipped in the backend, not a user configuration problem.","triggerScenarios":"svchost.ForComparison(genericHostname) at backend.go:207 returns an error. Because genericHostname is the hardcoded literal \"localterraform.com\" (a syntactically valid hostname), this branch is effectively unreachable in any correct build. The only way to hit it is if the constant is patched/overridden to an invalid hostname (empty string, underscores, disallowed chars, or >63-byte label), or svchost's validation rules change to reject it.","commonSituations":"A downstream fork or custom build modifies genericHostname to an invalid value; an svchost library upgrade tightens validation so the constant no longer parses; or test/mocking replaces the constant. End users on official builds will not see this.","solutions":["If you are running an official Terraform build, file a bug report — this path is documented as unreachable.","If running a fork/custom build, restore genericHostname to the valid literal \"localterraform.com\" (or another RFC-compliant hostname).","Check whether an svchost dependency upgrade changed validation rules; pin or update hashicorp/go-svchost to a compatible version.","As a user there is no configuration fix — report the bug to the backend maintainer.","Verify no build-time flag/ldflag is overriding the constant."],"exampleFix":"// backend.go — the constant must be a valid hostname\n// before (invalid, triggers the bug):\n//   genericHostname = \"local_terraform.com\"   // underscore illegal\n// after:\nconst genericHostname = \"localterraform.com\"","handlingStrategy":"validation","validationCode":"// For a statically-defined hostname, validate at startup so an invalid constant fails fast and clearly.\nimport \"github.com/hashicorp/go-svchost\"\n\nfunc init() {\n  if _, err := svchost.ForComparison(genericHostname); err != nil {\n    panic(fmt.Sprintf(\"genericHostname constant %q is invalid: %v — this is a build bug\", genericHostname, err))\n  }\n}","typeGuard":"// Validate any hostname before passing to svchost.ForComparison.\nfunc isValidSvchost(h string) bool {\n  _, err := svchost.ForComparison(h)\n  return err == nil\n}","tryCatchPattern":"// This branch is documented unreachable; if reached, fail loudly with a bug report hint.\naliasHostname, err := svchost.ForComparison(genericHostname)\nif err != nil {\n  return nil, fmt.Errorf(\"BUG: static genericHostname %q failed validation (%w); \"+\n    \"please report this to the Terraform backend maintainers\", genericHostname, err)\n}","preventionTips":["Treat any occurrence as a bug: capture the exact Terraform build/version and report it.","If maintaining a fork, never override genericHostname with a non-RFC-compliant value.","Pin hashicorp/go-svchost to a version compatible with your Terraform build.","Add a unit test asserting svchost.ForComparison(genericHostname) succeeds for every build."],"tags":["remote-backend","hostname","service-discovery","bug","configuration","svchost"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}