Commit 97b7e052 authored by Marcia Ramos's avatar Marcia Ramos

Merge branch 'docs-add-troubleshooting-unable-lock' into 'master'

Add troubleshooting for Unable to lock terraform state

See merge request gitlab-org/gitlab!69538
parents a0d07108 176cf511
...@@ -429,3 +429,18 @@ query ProjectTerraformStates { ...@@ -429,3 +429,18 @@ query ProjectTerraformStates {
For those new to the GitLab GraphQL API, read For those new to the GitLab GraphQL API, read
[Getting started with GitLab GraphQL API](../../../api/graphql/getting_started.md). [Getting started with GitLab GraphQL API](../../../api/graphql/getting_started.md).
## Troubleshooting
### Unable to lock Terraform state files in CI jobs for `terraform apply` using a plan created in a previous job
When passing `-backend-config=` to `terraform init`, Terraform persists these values inside the plan
cache file. This includes the `password` value.
As a result, to create a plan and later use the same plan in another CI job, you might get the error
`Error: Error acquiring the state lock` errors when using `-backend-config=password=$CI_JOB_TOKEN`.
This happens because the value of `$CI_JOB_TOKEN` is only valid for the duration of the current job.
As a workaround, use [http backend configuration variables](https://www.terraform.io/docs/language/settings/backends/http.html#configuration-variables) in your CI job,
which is what happens behind the scenes when following the
[Get started using GitLab CI](#get-started-using-gitlab-ci) instructions.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment