{"record":{"id":"627e653c1fff08d9","repo":"hashicorp/terraform","slug":"error-parsing-q-as-a-provider-address-w","errorCode":null,"errorMessage":"Error parsing %q as a provider address: %w","messagePattern":"Error parsing %q as a provider address: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/reattach/reattach.go","lineNumber":59,"sourceCode":"\t\ttype reattachConfig struct {\n\t\t\tProtocol        string\n\t\t\tProtocolVersion int\n\t\t\tAddr            struct {\n\t\t\t\tNetwork string\n\t\t\t\tString  string\n\t\t\t}\n\t\t\tPid  int\n\t\t\tTest bool\n\t\t}\n\t\tvar m map[string]reattachConfig\n\t\terr := json.Unmarshal([]byte(in), &m)\n\t\tif err != nil {\n\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid format for %s: %w\", TF_REATTACH_PROVIDERS, err)\n\t\t}\n\t\tfor p, c := range m {\n\t\t\ta, diags := addrs.ParseProviderSourceString(p)\n\t\t\tif diags.HasErrors() {\n\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Error parsing %q as a provider address: %w\", a, diags.Err())\n\t\t\t}\n\t\t\tvar addr net.Addr\n\t\t\tswitch c.Addr.Network {\n\t\t\tcase \"unix\":\n\t\t\t\taddr, err = net.ResolveUnixAddr(\"unix\", c.Addr.String)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid unix socket path %q for %q: %w\", c.Addr.String, p, err)\n\t\t\t\t}\n\t\t\tcase \"tcp\":\n\t\t\t\taddr, err = net.ResolveTCPAddr(\"tcp\", c.Addr.String)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Invalid TCP address %q for %q: %w\", c.Addr.String, p, err)\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn unmanagedProviders, fmt.Errorf(\"Unknown address type %q for %q\", c.Addr.Network, p)\n\t\t\t}\n\t\t\tunmanagedProviders[a] = &plugin.ReattachConfig{\n\t\t\t\tProtocol:        plugin.Protocol(c.Protocol),","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/getproviders/reattach/reattach.go#L41-L77","documentation":"Thrown by reattach.ParseReattachProviders while iterating the JSON map in the TF_REATTACH_PROVIDERS environment variable: each map key must itself be a valid provider source address. addrs.ParseProviderSourceString rejected the key, so the entry cannot be mapped to an addrs.Provider. This stops all reattach setup because the offending key is uninterpretable.","triggerScenarios":"Calling ParseReattachProviders (or os.Getenv-based consumers like IsProviderReattached) with TF_REATTACH_PROVIDERS JSON whose top-level object key fails ParseProviderSourceString, e.g. an empty key, a key with more than three slash-separated parts, or characters disallowed in a hostname/namespace/type.","commonSituations":"Provider developers hand-editing TF_REATTACH_PROVIDERS; a debug build printing the key with extra whitespace or quotes; copying a source string from terraform registry UI that includes a leading '//' or scheme; migrating an old config that used a bare display name with slashes.","solutions":["Re-read the file:line cited in the error and fix the TF_REATTACH_PROVIDERS JSON key to a valid provider source (\"type\", \"namespace/type\", or \"hostname/namespace/type\").","Validate the address with addrs.ParseProviderSourceString in a small Go snippet before exporting the env var.","If the process is auto-generated by tf-providershim/exec, regenerate it so the key matches the provider's declared source string."],"exampleFix":"// before\nos.Setenv(\"TF_REATTACH_PROVIDERS\", `{\"foo/bar/baz/qux\": {\"Protocol\":\"grpc\"}}`)\n// after\nos.Setenv(\"TF_REATTACH_PROVIDERS\", `{\"registry.terraform.io/hashicorp/foo\": {\"Protocol\":\"grpc\"}}`)","handlingStrategy":"validation","validationCode":"import \"github.com/hashicorp/terraform/internal/addrs\"\n\n// Validate every key of the TF_REATTACH_PROVIDERS JSON before setting the env var.\nfunc validateProviderKeys(rawJSON string) error {\n    var m map[string]json.RawMessage\n    if err := json.Unmarshal([]byte(rawJSON), &m); err != nil {\n        return err\n    }\n    for k := range m {\n        if _, diags := addrs.ParseProviderSourceString(k); diags.HasErrors() {\n            return fmt.Errorf(\"invalid provider source key %q: %w\", k, diags.Err())\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always generate TF_REATTACH_PROVIDERS from the provider's launcher rather than hand-editing.","Treat each top-level JSON key as a provider source address, not a display name.","Validate keys with addrs.ParseProviderSourceString in test setup before exporting the env var."],"tags":["terraform","reattach","provider-config","tf-reattach-providers"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}