{"record":{"id":"fc6850e7a79bd4fd","repo":"hashicorp/terraform","slug":"invalid-hostname","errorCode":null,"errorMessage":"invalid hostname","messagePattern":"invalid hostname","errorType":"validation","errorClass":"ErrInvalidHostname","httpStatus":null,"severity":"error","filePath":"internal/cloud/cloudplan/saved_plan.go","lineNumber":15,"sourceCode":"// Copyright IBM Corp. 2014, 2026\n// SPDX-License-Identifier: BUSL-1.1\npackage cloudplan\n\nimport (\n\t\"encoding/json\"\n\t\"errors\"\n\t\"io\"\n\t\"os\"\n\t\"strings\"\n)\n\nvar ErrInvalidRemotePlanFormat = errors.New(\"invalid remote plan format, must be 1\")\nvar ErrInvalidRunID = errors.New(\"invalid run ID\")\nvar ErrInvalidHostname = errors.New(\"invalid hostname\")\n\ntype SavedPlanBookmark struct {\n\tRemotePlanFormat int    `json:\"remote_plan_format\"`\n\tRunID            string `json:\"run_id\"`\n\tHostname         string `json:\"hostname\"`\n}\n\nfunc NewSavedPlanBookmark(runID, hostname string) SavedPlanBookmark {\n\treturn SavedPlanBookmark{\n\t\tRemotePlanFormat: 1,\n\t\tRunID:            runID,\n\t\tHostname:         hostname,\n\t}\n}\n\nfunc LoadSavedPlanBookmark(filepath string) (SavedPlanBookmark, error) {\n\tbookmark := SavedPlanBookmark{}\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/cloudplan/saved_plan.go#L1-L33","documentation":"ErrInvalidHostname is returned by cloudplan.LoadSavedPlanBookmark when the loaded JSON plan-bookmark (the tfplan artifact written when a cloud/remote plan is saved) has an empty Hostname field. The bookmark stores the run ID and cloud hostname so a later 'apply' can retrieve the remote plan; a missing hostname means the bookmark is unusable and likely not a real saved-plan bookmark at all. This is a data-integrity guard, not a network error.","triggerScenarios":"LoadSavedPlanBookmark reads a tfplan file, JSON-unmarshals it into SavedPlanBookmark, and at line 57-58 returns ErrInvalidHostname when bookmark.Hostname == \"\". Happens when the file exists and parsed as JSON but the \"hostname\" key is absent, null, or empty.","commonSituations":"A stale/corrupt tfplan left in the working dir from an aborted cloud run; a tfplan hand-edited or written by an older/incompatible Terraform version; a file that is valid JSON but not a saved-plan bookmark (e.g. a local backend plan json that lacks the remote_plan_format/run_id/hostname keys).","solutions":["Inspect the tfplan/plan file: confirm it has a \"hostname\" field matching your HCP Terraform / TFE hostname (e.g. app.terraform.io).","Regenerate the plan from scratch with 'terraform plan' against the cloud backend so a fresh, well-formed bookmark is written.","Delete the corrupt bookmark file and re-run 'terraform plan' to recreate it.","If persisting across Terraform versions, ensure both plan and apply run on the same Terraform version that wrote the bookmark."],"exampleFix":"// before: stale tfplan with no hostname key\n// {\"remote_plan_format\":1,\"run_id\":\"run-abc\"}\n//\n// after: regenerate so hostname is populated\n// $ terraform plan -out=tfplan    (cloud/remote backend fills hostname)\n// $ terraform show -json tfplan   (confirm hostname present)","handlingStrategy":"validation","validationCode":"// Before relying on a saved cloud plan bookmark, sanity-check the fields.\nfunc validBookmark(b cloudplan.SavedPlanBookmark) error {\n    if b.RemotePlanFormat != 1 {\n        return fmt.Errorf(\"unsupported plan format %d\", b.RemotePlanFormat)\n    }\n    if strings.TrimSpace(b.Hostname) == \"\" {\n        return errors.New(\"plan bookmark missing hostname; regenerate with 'terraform plan'\")\n    }\n    if !strings.HasPrefix(b.RunID, \"run-\") {\n        return fmt.Errorf(\"plan bookmark has invalid run ID %q\", b.RunID)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always regenerate the plan with the same Terraform version that will apply it.","Do not hand-edit tfplan files; treat them as opaque artifacts.","Discard stale tfplan files in CI between runs to avoid loading corrupt bookmarks."],"tags":["cloud-plan","bookmark","hostname","tfplan","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}