Can't unlock Gitab hosted Terraform State file via API call
Summary
Customer is unable to unlock terraform state hosted in Gitlab via API call.
Steps to reproduce
Customer has created a project based on https://gitlab.com/nicholasklick/terraform-example/-/blob/master/.gitlab/Terraform.gitlab-ci.yml
they tried the following commands:
curl --header "PRIVATE-TOKEN: <MYTOKEN>" https://gitlab.com/api/v4/projects/20733912/terraform/state/primary_hub/lock
and
curl --header "PRIVATE-TOKEN: <MYTOKEN>" https://gitlab.com/api/v4/projects/20733912/terraform/state/primary_hub/unlock
Both failed with {"error":"404 Not Found"}
To confirm that the state file existed they then ran:
curl --header "PRIVATE-TOKEN: <MYTOKEN>" https://gitlab.com/api/v4/projects/20733912/terraform/state/primary_hub
Which outputted the contents of the state file.
The access token was give an API scope as documented at https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
The customer then created variables in GitLab Settings > CI / CD
called GITLAB_USER_LOGIN
and GITLAB_TF_PASSWORD
with their GitLab user
and the access token
.
They exported the variables as TF_USERNAME
and TF_PASSWORD
in .gitlab-ci.yml
so that they can be used by the runner image registry.gitlab.com/gitlab-org/terraform-images/stable:latest
as documented at https://gitlab.com/gitlab-org/terraform-images.
This worked successfully until a Terraform crash which locked the managed backend.
The error from the pipeline:
+ terraform plan '-out=plan.cache'
Error: Error locking state: Error acquiring the state lock: HTTP remote state already locked: ID=450e834d-dc84-2a87-9bbd-751c127b10aa
This is a Gitlab.com
customer so we have access to the pipeline where the error happened (pipeline #192559082)
What is the current bug behavior?
API call to unlock terraform state file is failing with a 404 HTTP error
What is the expected correct behavior?
API call should allow unlock the terraform state file hosted in Gitlab
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com