hashicorp/terraform · critical
errStateStoreInitDiag requires a non-nil reason argument
Error message
errStateStoreInitDiag requires a non-nil reason argument
What it means
Programmer-error panic in errStateStoreInitDiag: the helper requires a non-nil *ssInitReason, because it dereferences ir.Reason and ir.Subject. Passing nil is a coding mistake in internal callers, not a user input error.
Source
Thrown at internal/command/meta_backend_errors.go:203
return tfdiags.Sourceless(
tfdiags.Error,
"Backend initialization required, please run \"terraform state migrate\" or \"terraform init -reconfigure\"",
msg,
)
}
type ssInitReason struct {
MigrationNeeded bool
Reason string
Subject *hcl.Range
}
// errStateStoreInitDiag creates a diagnostic to present to users when
// users attempt to run a non-init command after making a change to their
// state_store configuration.
func errStateStoreInitDiag(ir *ssInitReason) tfdiags.Diagnostics {
if ir == nil {
panic("errStateStoreInitDiag requires a non-nil reason argument")
}
var msg string
msg += fmt.Sprintf("Reason: %s\n\n", ir.Reason)
msg += `A "state store" is an interface that Terraform uses to store state.
Changes to state store configurations require reinitialization, and a
decision whether to migrate any existing state or not.
If you want to migrate existing state using the current configuration,
please run "terraform state migrate".
If you don't want to migrate existing state and just reconfigure how state is
stored using the current configuration, please run "terraform init -reconfigure".
If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.`View on GitHub (pinned to d32a084675)
Solutions
- Report as a Terraform bug with the command/config that triggered it.
- If you call this helper internally, always construct a populated ssInitReason (MigrationNeeded, Reason, Subject) before invoking.
Example fix
// before
diags := errStateStoreInitDiag(nil)
// after
reason := &ssInitReason{Reason: "state_store changed", Subject: r}
diags := errStateStoreInitDiag(reason) Defensive patterns
Strategy: validation
Validate before calling
if ir == nil {
return tfdiags.Diagnostics{}.Append(tfdiags.Sourceless(tfdiags.Error, "missing state-store init reason", "..."))
}
return errStateStoreInitDiag(ir) Prevention
- Always construct a populated *ssInitReason before calling errStateStoreInitDiag.
- Treat this as an internal coding error if it surfaces.
- Add a unit test that asserts callers never pass nil.
When it happens
Trigger: Internal code calling errStateStoreInitDiag(nil) instead of building an ssInitReason struct; typically after a refactor or in a new code path that detects a state-store init reason but forgot to populate the struct.
Common situations: Internal Terraform bug; custom command wrappers that invoke errStateStoreInitDiag directly with nil.
Related errors
- nil config passed to StateStoreProviderFactoryFromConfigStat
- init (determineIfProviderTrusted): unexpected provider locat
- Unexpected command type in confirmProviderIsTrusted; this is
- When installing providers described in the config Terraform
- confirmFunc must not be nil
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/0fb0636b88aec5b3.
Report an issue: GitHub.