How to store the Terraform state in GitLab?
GitLab natively supports storing and locking Terraform states. So if your project uses both GitLab and Terraform, you might consider this option to save your Terraform states.
First of all, your Terraform configuration should contain the
following (typically in a file named providers.tf
):
Next, you will need to create a GitLab personal access token with all the scopes included. Save the token because GitLab will only show it to you once.
Now you can run the following steps:
Now running terraform plan
, terraform apply
and terraform state
will be done against the Terraform plan saved in GitLab.