This happened to me today. Here's my scenario:
- I use terraform workspaces.
- The backend is setup with S3 and dynamoDb.
- For me, the problem occurred on a new machine.
On a new machine, you first have to do terraform init
which in my case resulted in the below message
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Error refreshing 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:
In the above message, it is actually suggesting that the digest value in dynamoDB should be blank. When I inspected dynamoDB, there was a digest value against one of the records. I removed it and it started working.
So, in my opinion, here's what happened in my case:
- While experimenting with terraform, I was first trying things without workspaces and also once I introduced workspaces, I had done a few things in default workspace. Although I destroyed this infra but the digest value would have remained somehow in dynamoDB.
- On a new machine, doing
terraform init
initializes the terraform backend and will also bring in the workspaces that you have. In this case it will be default and any other workspace that you may have created.
- The default workspace is selected by default and since it is expected to be clean, the command failed on finding a digest value in dynamoDB.
Therefore, if you're dealing with the same problem, you can try this:
- Check if there is a digest value against the lockId that does not have "env:" in it. That is the one that belongs to default.
- Copy the digest somewhere in case what you're going to do next does not solve the problem and you would need to put it back.
- Clear the digest value.