Error: Error acquiring the state lock
Kesalahan berikut terjadi saat menjalankan perintah seperti terraform plan
dan terraform apply
.
$ terraform plan
╷
│ Error: Error acquiring the state lock
│
│ Error message: ConditionalCheckFailedException: The conditional request failed
│ Lock Info:
│ ID: 03d3b219-5ea1-47b9-71a5-3e93e7102fdf
│ Path: terraform.tfstate
│ Operation: OperationTypeApply
│ Who: ryuseikakujo@whos-who.local
│ Version: 1.5.2
│ Created: 2023-07-16 19:17:52.561678 +0000 UTC
│ Info:
│
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.
Jika Anda telah mengonfigurasi Manajemen Kunci Keadaan dengan DynamoDB, Keadaan akan dikunci selama operasi apply
untuk mencegah beberapa pengguna memproses secara bersamaan. Biasanya, kunci akan dilepaskan ketika apply
selesai. Namun, jika operasinya terputus di tengah jalan, berkas Keadaan akan tetap terkunci.
Solusi
Gunakan perintah terraform force-unlock
. Ini memungkinkan Anda untuk membuka kunci secara manual.
$ terraform force-unlock --help
Usage: terraform [global options] force-unlock LOCK_ID
Manually unlock the state for the defined configuration.
This will not modify your infrastructure. This command removes the lock on the
state for the current workspace. The behavior of this lock is dependent
on the backend being used. Local state files cannot be unlocked by another
process.
Options:
-force Don't ask for input for unlock confirmation.
Nilai ID yang harus dimasukkan untuk LOCK_ID
dapat ditemukan dalam pesan kesalahan. (Dalam kasus saya, itu adalah 03d3b219-5ea1-47b9-71a5-3e93e7102fdf
)
$ terraform force-unlock 03d3b219-5ea1-47b9-71a5-3e93e7102fdf
Sebagai alternatif, Anda dapat menghapus kunci dengan menjalankan setiap perintah dengan opsi -lock=false
.
$ terraform apply --lock=false
Referensi