Access previous versions of Terraform state on Artifactory (remote backend type)?

Using a backend "remote", it’s easily possible store and use Artifactory for the Terraform state. It also does a nice job of versioning.

In case of issues, how would I actually use the previous versions? terraform state pull and the like don’t allow to specify the name of a specific state file.

So, suppose there are those files:

How would I use state.1708332113711.json?

Hi @com_hashicorp,

Terraform CLI itself only concerns itself with publishing new state snapshots and retrieving the most recent one. The remote state backend API does not include anything about older versions.

Therefore if you want to interact with older snapshots then you’d need to do that using Artifactory’s API directly. It’s Artifactory’s server that’s responsible for retaining the older versions, and Terraform CLI is not itself aware that it’s happening.

1 Like

Hi

Hm, thanks :confused:

Is there no way to configure the remote backend and force it to use how the state file is called on the remote side?

My configuration currently looks like this:

terraform {
  # …

  # Artifactory - "remote"
  backend "remote" {
    hostname     = "artifactory.….com"
    organization = "tci-terraform-terraformbackend-local"
    workspaces {
      name = "test"
    }
  }

  # …
}

Hi @com_hashicorp,

The design of the remote backend is to make the server responsible for all of the storage decisions, instead of specifying it manually in each configuration. Artifactory chose to implement this protocol and so presumably their server implementation has some built-in opinions about how that storage will be handled.

Therefore if there are any settings about those details I would expect them to be in the Artifactory server settings, rather than in the backend configuration. However, I’m not very familiar with Artifactory and so I can’t give any more detail than that. You could try asking JFrog for help as well, since they presumably know better how their server implementation of this protocol is designed.