{"record":{"id":"d1a282c5d5d5ff1e","repo":"hashicorp/terraform","slug":"saved-backend-configuration-is-invalid-w","errorCode":null,"errorMessage":"saved backend configuration is invalid: %w","messagePattern":"saved backend configuration is invalid: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":547,"sourceCode":"\n\t\t// The fully configured Pluggable is used as the instance of backend.Backend\n\t\tb = p\n\n\tdefault:\n\t\tsettings := plan.Backend\n\n\t\tf := backendInit.Backend(settings.Type)\n\t\tif f == nil {\n\t\t\tdiags = diags.Append(errBackendSavedUnknown{settings.Type})\n\t\t\treturn nil, diags\n\t\t}\n\t\tb = f()\n\t\tlog.Printf(\"[TRACE] Meta.BackendForLocalPlan: instantiated backend of type %T\", b)\n\n\t\tschema := b.ConfigSchema()\n\t\tconfigVal, err := settings.Config.Decode(schema.ImpliedType())\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"saved backend configuration is invalid: %w\", err))\n\t\t\treturn nil, diags\n\t\t}\n\n\t\tnewVal, validateDiags := b.PrepareConfig(configVal)\n\t\tdiags = diags.Append(validateDiags)\n\t\tif validateDiags.HasErrors() {\n\t\t\treturn nil, diags\n\t\t}\n\n\t\tconfigureDiags := b.Configure(newVal)\n\t\tdiags = diags.Append(configureDiags)\n\t\tif configureDiags.HasErrors() {\n\t\t\treturn nil, diags\n\t\t}\n\t}\n\n\t// If the backend supports CLI initialization, do it.\n\tif cli, ok := b.(backendrun.CLI); ok {","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L529-L565","documentation":"Appended as a diagnostic from `Meta.BackendForLocalPlan` when decoding the backend configuration saved inside a plan file (`settings.Config.Decode(schema.ImpliedType())`) fails. The plan embedded a serialized backend config blob that does not conform to the backend's current schema's implied type — i.e. the plan is structurally incompatible with the installed backend.","triggerScenarios":"`settings.Config` (a `hcl2shim`/cty-encoded value stored in the plan) cannot be decoded against the backend's `ConfigSchema().ImpliedType()`. This happens when the plan was created with a different backend schema version, a different backend type, or a corrupted/truncated plan file.","commonSituations":"Applying a plan created with an older Terraform/backend version on a newer one whose schema changed; applying a plan whose `backend` block type was changed between plan and apply; manually editing or transferring a plan file across incompatible versions; backend plugin upgrade changed its config schema.","solutions":["Recreate the plan with the current Terraform + backend versions: `terraform plan -out=tfplan` then `terraform apply tfplan`.","Ensure the same backend type and version are used for both plan and apply.","Do not reuse plan files across Terraform CLI upgrades — plans are not forward/backward compatible across schema changes.","If the backend config in the repo changed, run `terraform init -reconfigure` before re-planning."],"exampleFix":"# before: applying a stale/incompatible plan\nterraform apply old.tfplan\n# after: regenerate with current versions\nterraform init -reconfigure\nterraform plan -out=tfplan\nterraform apply tfplan","handlingStrategy":"validation","validationCode":"// Do not reuse plans across backend schema changes.\n// Record the Terraform + backend version that created a plan and refuse to apply\n// if the current versions differ.\nif planVersion != currentVersion {\n    return errors.New(\"plan created with incompatible backend schema; regenerate\")\n}","typeGuard":"null","tryCatchPattern":"// Decode failures are not retryable; the plan must be regenerated.\nconfigVal, err := settings.Config.Decode(schema.ImpliedType())\nif err != nil {\n    return fmt.Errorf(\"saved backend configuration is invalid: %w; recreate the plan\", err)\n}","preventionTips":["Regenerate plans whenever Terraform CLI or backend plugins are upgraded.","Use the same backend type and config for plan and apply.","Never edit or transfer plan files across versions."],"tags":["terraform","backend","plan","schema","decode","version-mismatch"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}