hashicorp/terraform · error

failed to decode state_store's nested provider config: %w

Error message

failed to decode state_store's nested provider config: %w

What it means

Counterpart to 774, but for the nested provider block's config. At statestore_config_state.go:129, s.Provider.Config(providerSchema) decodes the provider's ConfigRaw against the provider schema's implied cty type. Failure indicates the stored provider config doesn't conform to the current provider schema.

Source

Thrown at internal/command/workdir/statestore_config_state.go:131

//
// The state_store configuration schema is required in order to properly
// encode the state store-specific configuration settings.
func (s *StateStoreConfigState) PlanData(storeSchema *configschema.Block, providerSchema *configschema.Block, workspaceName string) (*plans.StateStore, error) {
	if s == nil {
		panic("PlanData called on a nil *StateStoreConfigState receiver. This is a bug in Terraform and should be reported.")
	}

	if err := s.Validate(); err != nil {
		return nil, fmt.Errorf("error when preparing state store config for planfile: %s", err)
	}

	storeConfigVal, err := s.Config(storeSchema)
	if err != nil {
		return nil, fmt.Errorf("failed to decode state_store config: %w", err)
	}
	providerConfigVal, err := s.Provider.Config(providerSchema)
	if err != nil {
		return nil, fmt.Errorf("failed to decode state_store's nested provider config: %w", err)
	}

	var providerVersion *version.Version
	switch s.ProviderSupplyMode {
	case getproviders.BuiltIn, getproviders.Reattached, getproviders.DevOverride:
		// For built-in providers, reattached providers, and developer overrides, we don't require version information to be present in the state file, so we should be tolerant of it being missing.
		// In this case we can just use a placeholder version that will never actually be used for anything, but allows us to avoid returning an error when trying to save state store data to a plan file.
		providerVersion = version.Must(version.NewVersion("0.0.0"))
	case getproviders.ManagedByTerraform:
		providerVersion = s.Provider.Version
	default:
		panic(fmt.Sprintf("State store provider %q (%s) has unknown supply mode %q. This is a bug in Terraform and should be reported.", s.Provider.Source.Type, s.Provider.Source.ForDisplay(), s.ProviderSupplyMode))
	}

	return plans.NewStateStore(s.Type, providerVersion, s.Provider.Source, storeConfigVal, storeSchema, providerConfigVal, providerSchema, workspaceName)
}

func (s *StateStoreConfigState) DeepCopy() *StateStoreConfigState {

View on GitHub (pinned to c9def3e214)

Solutions

  1. Re-run 'terraform init' to re-encode the provider config against the current provider schema.
  2. Follow the provider upgrade guide if mid-version migration.
  3. Inspect the wrapped cty error to find the offending provider argument.

Example fix

// before
Error: failed to decode state_store's nested provider config: ...attribute "region": string required

// after
$ rm -rf .terraform && terraform init
$ terraform plan -out=tfplan
Defensive patterns

Strategy: try-catch

Validate before calling

// Probe-decode the nested provider config before PlanData.
if _, err := s.Provider.Config(providerSchema); err != nil {
    return fmt.Errorf("nested provider config will not decode: %w", err)
}

Type guard

null

Try / catch

if _, err := s.PlanData(storeSchema, provSchema, ws); err != nil {
    if strings.Contains(err.Error(), "nested provider config") {
        // provider schema drift; re-init
    }
}

Prevention

When it happens

Trigger: s.Provider.Config(providerSchema) returns an error from ctyjson.Unmarshal — provider schema drift or corrupt provider ConfigRaw.

Common situations: Provider upgraded after the state_store record was written, changing nested provider argument types; partial write of provider config bytes.

Understand the failure class

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/999a4ca827597e41. Report an issue: GitHub.