{"record":{"id":"25bd9ce8e4769a1a","repo":"hashicorp/terraform","slug":"failed-to-read-state-file-from-v-v","errorCode":null,"errorMessage":"Failed to read state file from %v: %v","messagePattern":"Failed to read state file from (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/gcs/client.go","lineNumber":47,"sourceCode":"\tencryptionKey []byte\n\tkmsKeyName    string\n}\n\nfunc (c *remoteClient) Get() (payload *remote.Payload, diags tfdiags.Diagnostics) {\n\tctx := context.TODO()\n\tstateFileReader, err := c.stateFile().NewReader(ctx)\n\tif err != nil {\n\t\tif err == storage.ErrObjectNotExist {\n\t\t\treturn nil, diags\n\t\t} else {\n\t\t\treturn nil, diags.Append(fmt.Errorf(\"Failed to open state file at %v: %v\", c.stateFileURL(), err))\n\t\t}\n\t}\n\tdefer stateFileReader.Close()\n\n\tstateFileContents, err := ioutil.ReadAll(stateFileReader)\n\tif err != nil {\n\t\treturn nil, diags.Append(fmt.Errorf(\"Failed to read state file from %v: %v\", c.stateFileURL(), err))\n\t}\n\n\tstateFileAttrs, err := c.stateFile().Attrs(ctx)\n\tif err != nil {\n\t\treturn nil, diags.Append(fmt.Errorf(\"Failed to read state file attrs from %v: %v\", c.stateFileURL(), err))\n\t}\n\n\tresult := &remote.Payload{\n\t\tData: stateFileContents,\n\t\tMD5:  stateFileAttrs.MD5,\n\t}\n\n\treturn result, diags\n}\n\nfunc (c *remoteClient) Put(data []byte) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\tctx := context.TODO()","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/gcs/client.go#L29-L65","documentation":"After successfully opening the state object reader, Get() does ioutil.ReadAll. If the byte stream read fails partway (network reset mid-download, connection drop, reader error after decryption header), this wraps that read error. The object exists and opened; only the body read failed.","triggerScenarios":"Large state file download interrupted by network reset; GCS connection closed mid-stream; decryption of object body failed after headers; transient I/O.","commonSituations":"Flaky CI network downloading a large tfstate; GCS side throttling; intermittent connectivity to GCS; corrupted object.","solutions":["Retry the terraform operation (RefreshState is not idempotent-guaranteed but a transient read error usually clears on retry).","If persistent, verify object integrity with 'gsutil cp gs://...state .tfstate' and check for read errors.","Reduce state size (split resources / use workspaces) if downloads are routinely interrupted.","Check for a corrupted object: compare gsutil-stored MD5 against object metadata."],"exampleFix":"# recover (transient)\nterraform state pull   # retry\ngsutil cp gs://bucket/prefix/default.tfstate /tmp/check.tfstate && md5sum /tmp/check.tfstate","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var payload *remote.Payload\nfor attempt := 0; attempt < 3; attempt++ {\n    var diags tfdiags.Diagnostics\n    payload, diags = client.Get()\n    if !diags.HasErrors() { break }\n    time.Sleep(time.Duration(1<<attempt) * time.Second)\n}","preventionTips":["Keep state file sizes manageable (split workspaces) to reduce read failures.","Retry transient read errors with exponential backoff.","Monitor CI network reliability to GCS."],"tags":["gcs","gcp","state","network","io"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}