hashicorp/terraform · error

error marshaling config: %s

Error message

error marshaling config: %s

What it means

Top-level wrapper: jsonconfig.Marshal(config, schemas) failed while building the configuration section. Config serialization needs provider/module schemas to interpret the HCL, so failures usually stem from a missing schema.

Source

Thrown at internal/command/jsonplan/plan.go:344

	}

	// output.Checks
	if p.Checks != nil && p.Checks.ConfigResults.Len() > 0 {
		output.Checks = jsonchecks.MarshalCheckStates(p.Checks)
	}

	// output.PriorState
	if sf != nil && !sf.State.Empty() {
		output.PriorState, err = jsonstate.Marshal(sf, schemas)
		if err != nil {
			return nil, fmt.Errorf("error marshaling prior state: %s", err)
		}
	}

	// output.Config
	output.Config, err = jsonconfig.Marshal(config, schemas)
	if err != nil {
		return nil, fmt.Errorf("error marshaling config: %s", err)
	}

	// output.Changes.ActionInvocations
	if p.Changes.ActionInvocations != nil {
		if output.ActionInvocations, err = MarshalActionInvocations(p.Changes.ActionInvocations, schemas); err != nil {
			return nil, fmt.Errorf("error marshaling action invocations: %s", err)
		}
	}

	return json.Marshal(output)
}

func (p *plan) marshalPlanVariables(vars map[string]plans.DynamicValue, decls map[string]*configs.Variable) error {
	p.Variables = make(variables, len(vars))

	for k, v := range vars {
		val, err := v.Decode(cty.DynamicPseudoType)
		if err != nil {

View on GitHub (pinned to c9def3e214)

Solutions

  1. Run `terraform init` to install providers and modules.
  2. Verify module and provider version pins match what produced the plan.
  3. Regenerate the plan after `terraform init` succeeds cleanly.
Defensive patterns

Strategy: try-catch

Try / catch

out, err := jsonplan.Marshal(config, plan, sf, schemas)
if err != nil && strings.Contains(err.Error(), "marshaling config") {
    // provider/module schema missing; run terraform init
}
return err

Prevention

When it happens

Trigger: Reached on every full Marshal call. Config marshaling fails when a provider or module schema needed to decode a config block is unavailable or incompatible.

Common situations: Provider not initialized (terraform init not run); module source/version changed since the plan was made; provider version downgrade removing a schema; corrupt configuration.

Related errors


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