hashicorp/terraform · error
lock file %s not exists
Error message
lock file %s not exists
What it means
Raised by remoteClient.lockInfo() (cos/client.go:168) when the lock file object does not exist in COS (getObject reports exists==false). There is no lock metadata to read or release, so any lock-info-dependent operation cannot proceed.
Source
Thrown at internal/backend/remote-state/cos/client.go:168
info, infoErr := c.lockInfo()
if infoErr != nil {
lockErr.Err = errors.Join(lockErr.Err, infoErr)
} else {
lockErr.Info = info
}
return lockErr
}
// lockInfo returns LockInfo from lock file
func (c *remoteClient) lockInfo() (*statemgr.LockInfo, error) {
exists, data, checksum, err := c.getObject(c.lockFile)
if err != nil {
return nil, err
}
if !exists {
return nil, fmt.Errorf("lock file %s not exists", c.lockFile)
}
info := &statemgr.LockInfo{}
if err := json.Unmarshal(data, info); err != nil {
return nil, err
}
info.ID = checksum
return info, nil
}
// getObject get remote object
func (c *remoteClient) getObject(cosFile string) (exists bool, data []byte, checksum string, err error) {
rsp, err := c.cosClient.Object.Get(c.cosContext, cosFile, nil)
if rsp == nil {
log.Printf("[DEBUG] getObject %s: error: %v", cosFile, err)
err = fmt.Errorf("failed to open file at %v: %v", cosFile, err)View on GitHub (pinned to c9def3e214)
Solutions
- Verify whether another run already released the lock; if so, the state is free to use.
- If the tag lock remains, delete the tencentcloud-terraform-lock tag manually.
- Re-run the terraform operation once the lock file and tag are both gone.
Defensive patterns
Strategy: try-catch
Validate before calling
// Check lock file existence before relying on lock info
exists, _, _, _ := c.getObject(c.lockFile)
if !exists {
// no lock present; nothing to unlock
return nil
} Try / catch
// Treat a missing lock file as 'already unlocked' rather than fatal
_, err := c.lockInfo()
if err != nil && strings.Contains(err.Error(), "not exists") {
return nil // lock already gone
} Prevention
- Idempotently handle unlock - a missing lock file is usually fine.
- Coordinate runs so only one process manages a lock at a time.
- Do not delete the lock file out-of-band while a run is active.
When it happens
Trigger: lockInfo() (called by Unlock and lockError) finds the lock file absent - typically because the lock was already released, manually deleted, or never created.
Common situations: Another process already unlocked the state; the lock file object was deleted out-of-band; trying to unlock a state that was never locked.
Related errors
- lock file %s exists
- Failed to lock cos state: %s
- Unlocking the state file on TencentCloud cos backend failed:
- lock id mismatch, %v != %v
- prefix must not start with '/' or './'
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/27812425c9282579.
Report an issue: GitHub.