Terraform failed to acquire state lock: 403: Access denied., forbidden
2022-11-17
Problem
We stored Terraform state in gcs. For some reasons, we got this error randomly when running on BitBucket pipelines:
1╷ 2│ Error: Error acquiring the state lock 3│ 4│ Error message: 2 errors occurred: 5│ * writing 6│ "gs://bucket/path/to/default.tflock" 7│ failed: googleapi: Error 403: Access denied., forbidden 8│ * storage: object doesn't exist 9│ 10│ 11│ 12│ Terraform acquires a state lock to protect the state from being written 13│ by multiple users at the same time. Please resolve the issue above and try 14│ again. For most commands, you can disable locking with the "-lock=false" 15│ flag, but this is not recommended. 16╵