{"record":{"id":"d0ca8fbdb1f7f301","repo":"hashicorp/terraform","slug":"nil-config-passed-to-statestoreproviderfactoryfrom","errorCode":null,"errorMessage":"nil config passed to StateStoreProviderFactoryFromConfigState","messagePattern":"nil config passed to StateStoreProviderFactoryFromConfigState","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/meta_backend.go","lineNumber":3018,"sourceCode":"\t\t\tSeverity: hcl.DiagError,\n\t\t\tSummary:  \"Provider unavailable\",\n\t\t\tDetail: fmt.Sprintf(\"The provider %s (%q) is required to initialize the %q state store, but the matching provider factory is missing. This is a bug in Terraform and should be reported.\",\n\t\t\t\tconfig.Provider.Name,\n\t\t\t\tconfig.ProviderAddr,\n\t\t\t\tconfig.Type,\n\t\t\t),\n\t\t\tSubject: &config.TypeRange,\n\t\t})\n\t}\n\n\treturn factory, diags\n}\n\nfunc (m *Meta) StateStoreProviderFactoryFromConfigState(cfgState *workdir.StateStoreConfigState) (providers.Factory, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tif cfgState == nil {\n\t\tpanic(\"nil config passed to StateStoreProviderFactoryFromConfigState\")\n\t}\n\n\tif cfgState.Provider == nil || cfgState.Provider.Source.IsZero() {\n\t\t// This should not happen; this data is populated when storing config state\n\t\treturn nil, diags.Append(&hcl.Diagnostic{\n\t\t\tSeverity: hcl.DiagError,\n\t\t\tSummary:  \"Unknown provider used for state storage\",\n\t\t\tDetail:   \"Terraform could not find the provider used with the state_store. This is a bug in Terraform and should be reported.\",\n\t\t})\n\t}\n\n\tfactories, err := m.ProviderFactories()\n\tif err != nil {\n\t\t// This may happen if the provider isn't present in the provider cache.\n\t\t// This should be caught earlier by logic that diffs the config against the backend state file.\n\t\treturn nil, diags.Append(&hcl.Diagnostic{\n\t\t\tSeverity: hcl.DiagError,\n\t\t\tSummary:  \"Provider unavailable\",","sourceCodeStart":3000,"sourceCodeEnd":3036,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L3000-L3036","documentation":"Programmer-error panic in StateStoreProviderFactoryFromConfigState: callers must pass a non-nil *workdir.StateStoreConfigState. Passing nil panics immediately because the function dereferences cfgState.Provider. It guards against an internal coding mistake rather than user input.","triggerScenarios":"An internal Terraform code path invoking StateStoreProviderFactoryFromConfigState(nil), e.g. when the state store config was never loaded or a refactored caller forgot to populate the pointer.","commonSituations":"Terraform internal bug after a refactor, custom command wrappers invoking this Meta method with a nil config, or a corrupted working-dir state file that produced nil on load.","solutions":["Report as a Terraform bug with the full command and config that triggered it.","Ensure your working directory state (.terraform/terraform.tfstate) is not corrupted; re-run terraform init cleanly.","If calling this method from tooling, always check for nil cfgState before invoking."],"exampleFix":"// before\ncfgState := loadedConfig() // may be nil\nfactory, diags := m.StateStoreProviderFactoryFromConfigState(cfgState)\n\n// after\ncfgState := loadedConfig()\nif cfgState == nil {\n    return providers.Factory(nil), tfdiags.Diagnostics{}.Append(...)\n}\nfactory, diags := m.StateStoreProviderFactoryFromConfigState(cfgState)","handlingStrategy":"validation","validationCode":"// Caller guard before invoking the Meta method.\nif cfgState == nil {\n    return nil, tfdiags.Diagnostics{}.Append(tfdiags.Sourceless(tfdiags.Error, \"no state store config\", \"...\"))\n}\nreturn m.StateStoreProviderFactoryFromConfigState(cfgState)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call StateStoreProviderFactoryFromConfigState with nil.","If writing internal Terraform code, document the non-nil precondition.","Re-run terraform init cleanly if the working-dir state is suspect."],"tags":["terraform","state-store","panic","internal-bug","nil-check"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}