Problem
When you attempt to upload a new state file version to a workspace in HCP Terraform or Terraform Enterprise, you may encounter the following 412 Precondition Failed error.
{
"errors": [
{
"status": "412",
"title": "Precondition Failed",
"detail": "The serial provided in the state file is not greater than the serial\ncurrently known remotely. This means that there may be an update performed\nsince your version of that state. Update to the latest state to resolve\nconflicts and try again"
}
]
}Cause
This error occurs when the serial number in the API request payload is less than the serial number of the latest state version that already exists in the workspace. HCP Terraform and Terraform Enterprise require the new state's serial number to be greater than the current version's serial to prevent overwriting state with an older version.
The API enforces this check on the serial value in the request payload, not the value within the state file itself.
Solution
To resolve this issue, you must update the serial number in your API request to be greater than the current remote state's serial.
- Determine the current serial value for the latest state version in the workspace by using the Current State Version API endpoint.
- In your JSON payload, increment the integer value for
data.attributes.serialto be greater than the value you retrieved in the previous step. - Submit the API request again to create the new state version.