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

  1. Verify whether another run already released the lock; if so, the state is free to use.
  2. If the tag lock remains, delete the tencentcloud-terraform-lock tag manually.
  3. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/27812425c9282579. Report an issue: GitHub.