ARTIFACTORY: How to deal with Terraform client returning “Error saving state: Error uploading state: 400 Bad Request” while Terraform apply using Backend repository in JFrog Artifactory

ARTIFACTORY: How to deal with Terraform client returning “Error saving state: Error uploading state: 400 Bad Request” while Terraform apply using Backend repository in JFrog Artifactory

AuthorFullName__c
Elumalai Ganesan, Elina Floim
articleNumber
000005723
FirstPublishedDate
2023-05-17T10:55:31Z
lastModifiedDate
2025-07-22
VersionNumber
2


As a result of recent changes implemented in Terraform version 1.38 and above, there have been modifications to the behavior of the "apply" and "destroy" commands. Prior to version 1.38, when applying and then destroying without any existing resources, a new state would be created. However, in the new version, this behavior has been altered such that no new state is generated under such circumstances.

Consequently, when executing the "terraform apply" and subsequently the "terraform destroy" commands, the previous behavior would result in the creation of three files in the repository: "state.latest.json," "state.{timestamp}.json," and "workspace.json." Conversely, in the updated version, only two files are generated: "state.latest.json" and "workspace.json." 
Therefore, attempting these commands using the new Terraform client will trigger the following error message: 

 

2023-04-04T13:49:38.361Z [1;32m[jfrt ][0;39m [1;31m[ERROR][0;39m [2ddf644bc22f3bc ] [aformLocalStateRepoHandler:277] [p-nio-8081-exec-2432] - Failed to create new state version at terraform-backend/workspaces/test/state.latest.json: Could not find item at terraform-backend:workspaces/test/state.latest.json

 

Terraform Client output:
│ Error: Failed to save state
│ Error saving state: Error uploading state: 400 Bad Request╷
│ Error: Failed to persist state to backend
│ The error shown above has prevented Terraform from writing the updated state to the configured backend. To allow for recovery, the state has been written to the file
│ "errored.tfstate" in the current working directory.
│ Running "terraform apply" again at this point will create a forked state, making it harder to recover.
││ To retry writing this state, use the following command:
│    terraform state push errored.tfstate


The modification has been reported internally via Jira (RTDEV-29949) and has been resolved in the most recent versions, including 7.55.10 and 7.56. Therefore, to overcome you may can upgrade Artifactory to the latest version.