【问题标题】:gitlab-ci terraform state lock file eradicationgitlab-ci terraform 状态锁文件根除
【发布时间】:2020-10-26 04:34:59
【问题描述】:

在尝试迁移我的后端配置以通过 gitlab 使用新的状态存储时,我遇到了这个光荣的问题:我的状态被锁定。

  • 我无法强制解锁状态,因为后端需要重新初始化
  • 我无法强制解锁 - 强制解锁状态,因为后端需要重新初始化
  • 我无法使用 -lock=false 设置后端,因为启动这整个混乱的相同凭据似乎无法推送除有毒锁定令牌以外的其他内容:
Error: Error copying state from the previous "local" backend to the newly configured
"http" backend:
    Failed to upload state: POST http://internal.host/api/v4/projects/14/terraform/state/project-name giving up after 3 attempts

我忍无可忍了。我确实尝试检查 /var/log/gitlab/gitlab-rails/production_json.log 中的喋喋不休是否提供了相关的内容,并且对它没有更多的把握和理智。

是否有没有任何守门的sudo pretty-please-with-sugar-on-top-clean-the-fn-lock 命令?

【问题讨论】:

  • 注意:我已经通过使用不同的 URL 进行锁定临时解决了这个问题。我仍然想知道一种可靠的方法来彻底杀死那把锁。

标签: terraform gitlab-ci


【解决方案1】:

我在将 terraform 状态文件从 s3 迁移到 gitlab 时遇到了同样的问题。 我造成了这个问题,因为我在 backend_config unlock_address 中有一个拼写错误,并且我在 init 仍在运行时插入了 Control+C。 terraform init 没有要求我将状态从 s3 迁移到 gitlab,但我被锁定了,强制解锁无论如何都不起作用。

我带来的解决方案:

  1. 将 backend.tf 配置为使用之前使用的 lock_address 作为解锁地址并重新初始化 terraform。
  2. Terraform 计划现在应该可以正常工作了。
  3. 重新配置 backend.tf 以继续状态迁移。通过再次迁移,使用您想要的 URL 重新初始化 terraform 状态 URL。

例如,这是我使用的 terraform init,其中所需的地址是 并且我有一个错字 。 我用 control+C 打断了:

terraform init \
 -backend-config="address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name>" \ 
 -backend-config="lock_address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name>/lock" \    
 -backend-config="unlock_address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name_B>/lock" \
 -backend-config="username=<user>" \     
 -backend-config="password=<password>" \   
 -backend-config="lock_method=POST" \    
 -backend-config="unlock_method=DELETE" \
 -backend-config="retry_wait_min=5"

这就是我重新配置 terraform init 以绕过锁的方式。

terraform init \
 -backend-config="address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name_B>" \ 
 -backend-config="lock_address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name_B>/lock" \    
 -backend-config="unlock_address=https://<gitlab_url>/api/v4/projects/<ProjectID>/terraform/state/<TF_State_Name_B>/lock" \
 -backend-config="username=<user>" \     
 -backend-config="password=<password>" \   
 -backend-config="lock_method=POST" \    
 -backend-config="unlock_method=DELETE" \
 -backend-config="retry_wait_min=5"

最后,你应该重新配置到想要的地址。

【讨论】:

    猜你喜欢
    • 2022-06-24
    • 2021-09-30
    • 2019-11-13
    • 2020-11-03
    • 2020-07-07
    • 2019-10-26
    • 2020-12-24
    • 2021-12-15
    • 2013-02-26
    相关资源
    最近更新 更多