Evan Kroske
Evan Kroske

Reputation: 4554

How can I roll back the Terraform state of my config in S3?

I've messed up the Terraform state of a config, so I'd like to replace the existing state with a previous version. The state is stored in S3, and I'm using a lock table. Here's what I tried:

  1. I downloaded an old version of the state from S3 and uploaded it to S3, replacing the existing version. Result of 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
    
  2. I updated the digest value stored in the DynamoDB table. Result of 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.
    

How can I roll back/revert/recover/restore the Terraform state to an older version?

Upvotes: 5

Views: 7792

Answers (1)

BMW
BMW

Reputation: 45313

Did you try force unlock command? It works for me when dealing with the locking issue.

terraform force-unlock LOCK_ID

The lock id is the id in above output:

ID:        XXXXXXX

Updated by @alexsandarT

If this does not work, use terraform force-unlock -force LOCK_ID

Upvotes: 5

Related Questions