{"record":{"id":"ef160c201e8aa8e4","repo":"hashicorp/terraform","slug":"workspace-data-missing-from-plan-file-current-wor","errorCode":null,"errorMessage":"Workspace data missing from plan file. Current workspace is %q. This is a bug in Terraform and should be reported.","messagePattern":"Workspace data missing from plan file\\. Current workspace is %q\\. This is a bug in Terraform and should be reported\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/command/meta_backend.go","lineNumber":351,"sourceCode":"\tvar diags tfdiags.Diagnostics\n\n\t// Check the workspace name in the plan matches the current workspace\n\tcurrentWorkspace, err := m.Workspace()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"error determining current workspace when initializing a backend from the plan file: %w\", err))\n\t\treturn nil, diags\n\t}\n\tvar plannedWorkspace string\n\tvar isCloud bool\n\tswitch {\n\tcase plan.StateStore != nil:\n\t\tplannedWorkspace = plan.StateStore.Workspace\n\t\tisCloud = false\n\tcase plan.Backend != nil:\n\t\tplannedWorkspace = plan.Backend.Workspace\n\t\tisCloud = plan.Backend.Type == \"cloud\"\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Workspace data missing from plan file. Current workspace is %q. This is a bug in Terraform and should be reported.\", currentWorkspace))\n\t}\n\tif currentWorkspace != plannedWorkspace {\n\t\treturn nil, diags.Append(&errWrongWorkspaceForPlan{\n\t\t\tcurrentWorkspace: currentWorkspace,\n\t\t\tplannedWorkspace: plannedWorkspace,\n\t\t\tisCloud:          isCloud,\n\t\t})\n\t}\n\n\tvar b backend.Backend\n\tswitch {\n\tcase plan.StateStore != nil:\n\t\tsettings := plan.StateStore\n\n\t\t// BackendForLocalPlan is used in the context of an apply command using a plan file,\n\t\t// so we can read locks directly from the lock file and trust it contains what we need.\n\t\tlocks, lockDiags := m.lockedDependencies()\n\t\tdiags = diags.Append(lockDiags)","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L333-L369","documentation":"A panic in `meta_backend.go:351` during `BackendForLocalPlan`/plan application. When deciding which workspace a plan targets, the code switches on `plan.StateStore` vs `plan.Backend`; if BOTH are nil (neither workspace source is present) it panics, naming the current workspace and explicitly calling it 'a bug in Terraform'. A valid plan file always carries exactly one of these.","triggerScenarios":"Applying a saved plan file (`terraform apply tfplan`) where the serialized plan object has neither a `backend` block nor a `state_store` block. This indicates the plan was produced by a broken/corrupt serialization or a binary with a regression in plan encoding.","commonSituations":"Corrupted plan file; a plan saved by an experimental or patched Terraform that omitted backend metadata; partial write of a plan artifact (disk full, killed mid-write); version mismatch between plan writer and applier.","solutions":["Regenerate the plan with a fresh `terraform plan -out=tfplan` using the current binary, then apply.","Delete the suspect plan file and re-plan; do not retry the corrupted artifact.","If it recurs on a freshly generated plan, report a Terraform bug with the backend/state_store configuration and terraform version.","Ensure the working directory has the backend/state_store block configured and `terraform init` has completed."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Go: sanity-check a plan carries backend/state-store workspace data before applying\nfunc ensurePlanHasWorkspace(p *plans.Plan) error {\n\tif p.Backend == nil && p.StateStore == nil {\n\t\treturn errors.New(\"plan file is missing backend/state_store data; regenerate with terraform plan\")\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"// Go: recover during plan-driven backend init\ndefer func() {\n\tif r := recover(); r != nil {\n\t\terr = fmt.Errorf(\"plan file appears corrupt (%v); regenerate it with terraform plan\", r)\n\t}\n}()\nbackend, err := m.BackendForLocalPlan(plan)","preventionTips":["Regenerate plans with a fresh `terraform plan -out` rather than reusing old artifacts.","Do not downgrade Terraform between plan and apply.","Ensure `terraform init` completed and the backend/state_store block is present before planning.","Discard any plan file that was partially written (disk full / interrupted)."],"tags":["terraform","backend","plan-apply","panic","workspace","internal-bug","corrupt-plan"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}