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
articleNumber
000005723
ft:sourceType
Salesforce
FirstPublishedDate
2023-05-17T10:55:31Z
lastModifiedDate
2023-05-16
VersionNumber
1

Authors: Elumalai Ganesan and Elina Floim

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