Gitlab-managed terraform state cannot be found?

Problem to solve

I have a gitlab-managed terraform state that I have not used in a while, so I need to rerun the terraform init command with a new access token:

As usual, I go to the terraform states page https://gitlab.com/.../-/terraform, and use the “copy Terraform init command”, which gives me the following command to execute

export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
export TF_STATE_NAME=[tf_state_name]
terraform init \
    -backend-config="address=https://gitlab.com/api/v4/projects/[redacted]/terraform/state/$TF_STATE_NAME" \
    -backend-config="lock_address=https://gitlab.com/api/v4/projects/[redacted]/terraform/state/$TF_STATE_NAME/lock" \
    -backend-config="unlock_address=https://gitlab.com/api/v4/projects/[redacted]/terraform/state/$TF_STATE_NAME/lock" \
    -backend-config="username=[redacted]" \
    -backend-config="password=$GITLAB_ACCESS_TOKEN" \
    -backend-config="lock_method=POST" \
    -backend-config="unlock_method=DELETE" \
    -backend-config="retry_wait_min=5"

The command executes without problem, however when trying to run a terraform plan, I get the following error.


│ Error: Error acquiring the state lock
│ 
│ Error message: Unexpected HTTP response code 308
│ 
│ Terraform acquires a state lock to protect the state from being written
│ by multiple users at the same time. Please resolve the issue above and try
│ again. For most commands, you can disable locking with the "-lock=false"
│ flag, but this is not recommended.
╵

(I have not yet investigated where this redirects to, I will investigate and update the question)

Second, if I try without the lock terraform-plan -lock=false, I don’t get any error, but the output suggests that the state it is comparing to is blank, since it suggests to create the integrality of the resources I had defined.

Has there been a change on how gitlab manages states ?? My searches did not return anything, except that the documentation now reads GitLab-managed Terraform/OpenTofu state instead of just terraform.

Steps to reproduce

I’m a bit at a loss on how to reproduce this, since I dont have a second state I could try to re-init.

Versions

  • GitLab.com SaaS

Infrastructure-as-Code

  • Terraform/OpenTofu: Terraform v1.6.5 on linux_amd64

Browsing the project in GitLab under Operations > Terraform States should show you the existing states.