hashicorp/terraform · critical

nil config passed to StateStoreProviderFactoryFromConfigStat

Error message

nil config passed to StateStoreProviderFactoryFromConfigState

What it means

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.

Source

Thrown at internal/command/meta_backend.go:3018

			Severity: hcl.DiagError,
			Summary:  "Provider unavailable",
			Detail: 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.",
				config.Provider.Name,
				config.ProviderAddr,
				config.Type,
			),
			Subject: &config.TypeRange,
		})
	}

	return factory, diags
}

func (m *Meta) StateStoreProviderFactoryFromConfigState(cfgState *workdir.StateStoreConfigState) (providers.Factory, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics

	if cfgState == nil {
		panic("nil config passed to StateStoreProviderFactoryFromConfigState")
	}

	if cfgState.Provider == nil || cfgState.Provider.Source.IsZero() {
		// This should not happen; this data is populated when storing config state
		return nil, diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Unknown provider used for state storage",
			Detail:   "Terraform could not find the provider used with the state_store. This is a bug in Terraform and should be reported.",
		})
	}

	factories, err := m.ProviderFactories()
	if err != nil {
		// This may happen if the provider isn't present in the provider cache.
		// This should be caught earlier by logic that diffs the config against the backend state file.
		return nil, diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Provider unavailable",

View on GitHub (pinned to d32a084675)

Solutions

  1. Report as a Terraform bug with the full command and config that triggered it.
  2. Ensure your working directory state (.terraform/terraform.tfstate) is not corrupted; re-run terraform init cleanly.
  3. If calling this method from tooling, always check for nil cfgState before invoking.

Example fix

// before
cfgState := loadedConfig() // may be nil
factory, diags := m.StateStoreProviderFactoryFromConfigState(cfgState)

// after
cfgState := loadedConfig()
if cfgState == nil {
    return providers.Factory(nil), tfdiags.Diagnostics{}.Append(...)
}
factory, diags := m.StateStoreProviderFactoryFromConfigState(cfgState)
Defensive patterns

Strategy: validation

Validate before calling

// Caller guard before invoking the Meta method.
if cfgState == nil {
    return nil, tfdiags.Diagnostics{}.Append(tfdiags.Sourceless(tfdiags.Error, "no state store config", "..."))
}
return m.StateStoreProviderFactoryFromConfigState(cfgState)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/d0ca8fbdb1f7f301. Report an issue: GitHub.