{"record":{"id":"b3b82e05845b4b16","repo":"hashicorp/terraform","slug":"could-not-write-lock-info-for-q-s","errorCode":null,"errorMessage":"could not write lock info for %q: %s","messagePattern":"could not write lock info for %q: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/clistate/local_state.go","lineNumber":312,"sourceCode":"\t}\n\n\tinfo := statemgr.LockInfo{}\n\terr = json.Unmarshal(infoData, &info)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"state file %q locked, but could not unmarshal lock info: %s\", s.Path, err)\n\t}\n\treturn &info, nil\n}\n\n// write a new lock info file\nfunc (s *LocalState) writeLockInfo(info *statemgr.LockInfo) error {\n\tpath := s.lockInfoPath()\n\tinfo.Path = s.Path\n\tinfo.Created = time.Now().UTC()\n\n\terr := ioutil.WriteFile(path, info.Marshal(), 0600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not write lock info for %q: %s\", s.Path, err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":294,"sourceCodeEnd":316,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/clistate/local_state.go#L294-L316","documentation":"Thrown by LocalState.writeLockInfo when ioutil.WriteFile fails to persist the lock info JSON to the .tflock file with mode 0600. This runs during Lock to record who/what holds the lock. Failure means the lock info could not be written, even though the in-process and on-disk lock acquisition may have partly succeeded.","triggerScenarios":"The state file's directory is not writable; disk full; the path is on a read-only filesystem; permission denied on the existing .tflock file (owned by another user).","commonSituations":"State file on a read-only mount; CI environment where the state dir has restricted perms; a previous root-owned .tflock file blocking the current user; out-of-disk.","solutions":["Ensure the state file's directory is writable by the current user.","Remove or chown a stale .tflock file left by a prior root run: `sudo rm <statefile>.tflock`.","Check disk space and that the filesystem is mounted read-write.","Move state to a writable location and update -state or the backend config."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func stateDirWritable(statePath string) error {\n    dir, _ := filepath.Split(statePath)\n    if dir == \"\" { dir = \".\" }\n    probe, err := os.CreateTemp(dir, \".lock-test-*\")\n    if err != nil { return fmt.Errorf(\"cannot write lock info in %s: %w\", dir, err) }\n    probe.Close(); os.Remove(probe.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the state file's directory writable by all users who run Terraform.","Remove stale root-owned .tflock files before non-root runs.","Avoid read-only mounts for local state."],"tags":["state","locking","filesystem","permissions","local-backend"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}