{"record":{"id":"4ec94156b8102bbc","repo":"hashicorp/terraform","slug":"key-q-could-not-be-found","errorCode":null,"errorMessage":"Key %q could not be found","messagePattern":"Key %q could not be found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/consul/client.go","lineNumber":101,"sourceCode":"\tchunked, hash, chunks, pair, err := c.chunkedMode()\n\tif err != nil {\n\t\treturn nil, diags.Append(err)\n\t}\n\tif pair == nil {\n\t\treturn nil, diags\n\t}\n\n\tc.modifyIndex = pair.ModifyIndex\n\n\tvar payload []byte\n\tif chunked {\n\t\tfor _, c := range chunks {\n\t\t\tpair, _, err := kv.Get(c, nil)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, diags.Append(err)\n\t\t\t}\n\t\t\tif pair == nil {\n\t\t\t\treturn nil, diags.Append(fmt.Errorf(\"Key %q could not be found\", c))\n\t\t\t}\n\t\t\tpayload = append(payload, pair.Value[:]...)\n\t\t}\n\t} else {\n\t\tpayload = pair.Value\n\t}\n\n\t// If the payload starts with 0x1f, it's gzip, not json\n\tif len(payload) >= 1 && payload[0] == '\\x1f' {\n\t\tpayload, err = uncompressState(payload)\n\t\tif err != nil {\n\t\t\treturn nil, diags.Append(err)\n\t\t}\n\t}\n\n\tmd5 := md5.Sum(payload)\n\n\tif hash != \"\" && fmt.Sprintf(\"%x\", md5) != hash {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/consul/client.go#L83-L119","documentation":"In chunked mode, RemoteClient.Get (client.go:101) iterates the recorded chunk paths and reads each via kv.Get. If any chunk key returns a nil pair (deleted or never written), the state is incomplete and cannot be reconstructed, so this error is returned.","triggerScenarios":"Chunked state storage where one of the chunk sub-keys (e.g. tfstate/<path>/tfstate.<hash>/<n>) was deleted or missing between the index write and the read.","commonSituations":"Manual KV cleanup that removed chunk keys; a partial write failure; Consul data loss/expiry; another run's cleanup deleting the wrong tree.","solutions":["Restore the missing chunk keys from a Consul snapshot/backup.","Avoid manual deletion under the state path.","Ensure writes complete fully; list the Consul KV under the state path to find gaps."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# verify every declared chunk key still exists in Consul\nroot=\"tfstate/<path>\"\nchunks=\"$(consul kv get \"$root\" | jq -r '.chunks[]?')\"\nfor c in $chunks; do\n  consul kv get \"$c\" >/dev/null 2>&1 || echo \"MISSING chunk: $c\"\ndone","typeGuard":"// verify each chunk key resolves before reconstructing state\nfunc allChunksPresent(kv *consulapi.KV, chunks []string) bool {\n    for _, c := range chunks {\n        p, _, err := kv.Get(c, nil)\n        if err != nil || p == nil {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":null,"preventionTips":["Never manually delete under the state KV path.","Back up Consul (snapshots) so chunks can be restored.","Investigate partial write failures immediately."],"tags":["consul","state","storage","data-integrity"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}