{"record":{"id":"d3c076886b8853fd","repo":"hashicorp/terraform","slug":"can-t-show-a-saved-cloud-plan-unless-the-current-r","errorCode":null,"errorMessage":"can't show a saved cloud plan unless the current root module is connected to %s","messagePattern":"can't show a saved cloud plan unless the current root module is connected to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/show.go","lineNumber":307,"sourceCode":"\t} else if cp, ok := pf.Cloud(); ok {\n\t\tredacted := c.viewType != arguments.ViewJSON\n\t\tjsonPlan, err = c.getDataFromCloudPlan(cp, redacted)\n\t}\n\n\treturn plan, jsonPlan, stateFile, config, err\n}\n\nfunc (c *ShowCommand) getDataFromCloudPlan(plan *cloudplan.SavedPlanBookmark, redacted bool) (*cloudplan.RemotePlanJSON, error) {\n\t// Set up the backend\n\tb, diags := c.backend(\".\", c.viewType)\n\tif diags.HasErrors() {\n\t\treturn nil, errUnusable(diags.Err(), \"cloud plan\")\n\t}\n\t// Cloud plans only work if we're cloud.\n\tcl, ok := b.(*cloud.Cloud)\n\tif !ok {\n\t\terrMessage := fmt.Sprintf(\"can't show a saved cloud plan unless the current root module is connected to %s\", cl.AppName())\n\t\treturn nil, errUnusable(errors.New(errMessage), \"cloud plan\")\n\t}\n\n\tresult, err := cl.ShowPlanForRun(context.Background(), plan.RunID, plan.Hostname, redacted)\n\tif err != nil {\n\t\terr = errUnusable(err, \"cloud plan\")\n\t}\n\treturn result, err\n}\n\n// getDataFromPlanfileReader returns a plan, statefile, and config, extracted from a local plan file.\nfunc getDataFromPlanfileReader(planReader *planfile.Reader, allowLanguageExperiments bool, variableValues map[string]arguments.UnparsedVariableValue) (*plans.Plan, *statefile.File, *configs.Config, error) {\n\t// Get plan\n\tplan, err := planReader.ReadPlan()\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\n\t// Get statefile","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/show.go#L289-L325","documentation":"Returned by `ShowCommand.getDataFromCloudPlan` when the configured backend for the current working directory is not the HCP Terraform / TFE `cloud` backend, but the plan bookmark being shown is a remote cloud plan. The current backend type is asserted via `b.(*cloud.Cloud)`; on failure this error is produced. NOTE: there is a latent bug in the source — on the `!ok` branch `cl` is nil, so `cl.AppName()` will panic before this error is ever returned in builds without nil-guarding; treat any actual sighting as a potential panic.","triggerScenarios":"`terraform show <saved-plan>` is invoked with a `SavedPlanBookmark` produced by a cloud run, but the working directory's backend resolves to local, s3, remote, etc. — anything other than `*cloud.Cloud`.","commonSituations":"Checking out a saved cloud plan locally after switching the `backend`/`cloud` block to a local backend; running `terraform show` on a plan JSON copied from a cloud run in a directory that is not cloud-connected; CI that fetched a plan bookmark into a non-cloud workspace.","solutions":["Run `terraform show` in the directory whose backend is the same `cloud` block that produced the plan.","Ensure `terraform init` has configured the cloud backend (the `cloud` block is present and logged in).","If you only have the plan JSON, use `terraform show -json <file>` on the exported JSON instead of a cloud bookmark."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the backend is cloud before attempting to read a cloud plan:\nb, diags := c.backend(\".\", c.viewType)\nif diags.HasErrors() { return nil, errUnusable(diags.Err(), \"cloud plan\") }\ncl, ok := b.(*cloud.Cloud)\nif !ok {\n    name := \"HCP Terraform\"\n    return nil, errUnusable(errors.New(\"current backend is not a cloud backend\"), \"cloud plan\")\n}","typeGuard":"// isCloudBackend narrows the backend to the cloud type without dereferencing nil.\nfunc isCloudBackend(b backend.Backend) (*cloud.Cloud, bool) {\n    cl, ok := b.(*cloud.Cloud)\n    if !ok || cl == nil {\n        return nil, false\n    }\n    return cl, true\n}","tryCatchPattern":null,"preventionTips":["Run `terraform show` for cloud plans only in directories whose backend is the same `cloud` block.","Prefer exporting plan JSON (`-json`) for cross-environment inspection.","Mind the latent nil-deref: never call methods on a failed type-assertion result."],"tags":["show","cloud","backend-mismatch","plan","latent-bug","terraform-cli"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}