Terraform:获取状态锁时出错:ConditionalCheckFailedException

Terraform:获取状态锁时出错:ConditionalCheckFailedException,terraform,gitlab-ci,Terraform,Gitlab Ci,在我的管道中发生的地形平面图期间,我遇到以下错误: Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 9db590f1-b6fe-c5f2-2678-8804f089deba Path: ... Operation: OperationTypePl

在我的管道中发生的
地形平面图
期间,我遇到以下错误:

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.
这很奇怪,因为我肯定没有其他并行计划。
有办法解决这个问题吗?如何删除此锁?

看起来锁在上一个管道之后仍然存在。我必须使用以下命令删除它才能删除它:

terraform force-unlock -force 9db590f1-b6fe-c5f2-2678-8804f089deba
或者使用以下选项重新启动计划
-lock=false

terraform plan -lock=false ...
错误原因 当一个进程无法运行
terraform plan
terraform apply
时,通常会出现此错误。例如,如果网络连接中断或进程在完成之前终止。然后Terraform“认为”该进程仍在基础设施上工作,并阻止其他进程同时使用相同的基础设施和状态,以避免冲突

如错误消息中所述,您应该确保没有其他进程仍在运行(例如,来自其他开发人员或来自某些构建自动化)。如果你在这种情况下强制解锁,你可能会破坏你的地形状态,使其难以恢复

决议 如果没有其他进程仍在运行:运行此命令

地形强制解锁9db590f1-b6fe-c5f2-2678-8804f089deba

(其中数字id应替换为错误消息中提到的id)


如果您不确定是否有另一个进程正在运行,并且担心可能会使事情变得更糟,我建议您等待一段时间(如1小时),然后重试,然后在大约30分钟后重试。如果错误仍然存在,则很可能没有其他过程,如果terraform force unlock出现以下错误,则可以按照上述说明安全解锁: “其他进程无法解锁本地状态” 然后 打开正在运行的进程并终止进程以移除锁。 对于Windows:打开任务管理器并搜索terraform控制台进程
对于Linux:grep For terraform进程,并使用kill-9杀死terraform控制台进程对于在AWS上运行terraform时遇到此问题的任何人,请确保您是根据预期的配置文件运行的。我今天遇到了这个问题,意识到我需要切换我的个人资料:

$ AWS_PROFILE=another_one

Im获取无法检索锁信息:JSON输入意外结束