在terraform plan
期间发生了以下错误,该错误发生在我的管道中:
Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
Lock Info:
ID: 9db590f1-b6fe-c5f2-2678-8804f089deba
Path: ...
Operation: OperationTypePlan
Who: ...
Version: 0.12.25
Created: 2020-05-29 12:52:25.690864752 +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.
这很奇怪,因为我确定没有其他并行计划。 有办法解决吗?我该如何删除此锁?
答案 0 :(得分:10)
当一个进程无法运行terraform plan
或terraform apply
时,通常会出现此错误。例如,如果您的网络连接中断或该过程在完成之前终止。然后Terraform“认为”该进程仍在基础架构上运行,并阻止其他进程同时使用相同的基础架构和状态,以避免冲突。
如错误消息中所述,您应该确保确实没有其他进程在运行(例如,来自其他开发人员或某些构建自动化的进程)。如果您在这种情况下强制降频,则可能会破坏您的地形状态,使其难以恢复。
如果没有其他进程在运行,请运行此命令
terraform force-unlock 1598512097611489
(其中数字ID应替换为错误消息中提到的数字)
如果不确定是否正在运行其他进程,并且担心会使情况变得更糟,建议您等待一段时间(例如1h),然后重试,然后在30分钟后重试。如果错误仍然存在,则很可能确实没有其他进程,并且可以如上所述保存以进行解锁
答案 1 :(得分:8)
在上一个管道之后,锁似乎仍然存在。为了删除它,我必须使用以下命令将其删除:
terraform force-unlock -force 9db590f1-b6fe-c5f2-2678-8804f089deba
或使用以下选项-lock=false
terraform plan -lock=false ...
答案 2 :(得分:1)
如果 terraform force-unlock 出现以下错误: “本地状态不能被另一个进程解锁” 然后 打开正在运行的进程并杀死该进程以解除锁定。 对于 Windows:打开任务管理器并搜索 terraform 控制台进程 对于 Linux:grep 用于 terraform 进程并使用 kill -9
终止 terraform 控制台进程答案 3 :(得分:0)
对于在针对 AWS 运行 Terraform 时遇到此问题的任何人,请确保您针对预期的配置文件运行。我今天遇到了这个问题,并意识到我需要切换我的个人资料:
$ AWS_PROFILE=another_one
答案 4 :(得分:0)
GCP:就我而言,在 Google 云存储中将权限更改为“存储对象管理员”后问题已解决。
答案 5 :(得分:0)
即使我遇到了同样的问题并尝试了不同的命令
terraform force-unlock -force 和 terraform force-unlock kill that particular process id and run again
。
ps aux | grep terraform
和 sudo kill -9 <process_id>