如何在 S3 中回滚我的配置的 Terraform 状态?

Eva*_*ske 5 amazon-s3 terraform

我弄乱了配置的 Terraform 状态,所以我想用以前的版本替换现有状态。状态存储在 S3 中,我使用的是锁表。这是我尝试过的:

  1. 我从 S3 下载了旧版本的状态并将其上传到 S3,替换现有版本。结果tf plan

    Error: Error loading state: state data in S3 does not have the expected content.
    
    This may be caused by unusually long delays in S3 processing a previous state
    update.  Please wait for a minute or two and try again. If this problem
    persists, and neither S3 nor DynamoDB are experiencing an outage, you may need
    to manually verify the remote state and update the Digest value stored in the
    DynamoDB table to the following value: XXXXXX
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我更新了存储在 DynamoDB 表中的摘要值。结果tf plan

    Acquiring state lock. This may take a few moments...
    
    Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
      status code: 400, request id: XXXXXXX
    Lock Info:
      ID:        XXXXXXX
      Path:      XXXXXX
      Operation: OperationTypePlan
      Who:       XXXXXX
      Version:   0.10.8
      Created:   2017-11-07 23:54:50.505166265 +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.
    
    Run Code Online (Sandbox Code Playgroud)

如何将 Terraform 状态回滚/恢复/恢复/恢复到旧版本?

BMW*_*BMW 5

您是否尝试过强制解锁命令?它在处理锁定问题时对我有用。

terraform force-unlock LOCK_ID
Run Code Online (Sandbox Code Playgroud)

锁 ID 是上面输出中的 ID:

ID:        XXXXXXX
Run Code Online (Sandbox Code Playgroud)

由@alexsandarT 更新

如果这不起作用,请使用 terraform force-unlock -force LOCK_ID

  • 如果这不起作用,请使用 terraform force-unlock -force LOCK_ID - 这对我有用 (2认同)