Terraform state file versioning

As documentation explains about use GitLab as Terraform remote state backend. https://docs.gitlab.com/ee/user/infrastructure/terraform_state.html
It includes Terraform State Versioning feature. But when I’m trying to use this feature it shows only latest state version, no previous version show. any suggestion for this issue ? thanks.

Hey,

The only way that I can get access to the previous versions of my terraform states in gitlab is to get the url of the latest version and manually modify the url to get back to previous ones. Maybe there is a UI for this too but I couldn’t find anywhere.

Hello,

Hope you were able to find an answer. However, just in case not, I wanted to highlight that the page you linked has a section (not sure when it was added) about accessing old Terraform state file versions via the Gitlab API: GitLab-managed Terraform state | GitLab

Hello,

I have been trying to access the previous and current versions of my terraform state using the API but I am not sure how to check the versions.

I use this command; curl --header “Private-Token: <your_access_token>” “https://gitlab.example.com/api/v4/projects/<your_project_id>/terraform/state/<your_state_name>/versions/”

I am sure that there no authentication issues but I don’t know what to put in the part of the URL.

I tried the latest version from a state pull but that doesn’t work, I get; {“message”:“404 Not Found”}.

Is there an API call to list all the versions of the terraform state?

In the link I shared before, it’s clear you need the version serial number.

This is in the state when you access the latest state via https://gitlab.example.com/api/v4/projects/<your_project_id>/terraform/state/<your_state_name>

It’s the third line down: “serial”

Hi @tspearconquest

Sorry for the inconvenience and thank you for your patience.

Apparently I can’t read, lol.