Store your tfstate on GitLab

Fabrice CarrelFabrice Carrel
1 min read

You are already using GitLab for your project and you need a simple way to store and share your tfstate? Use your GitLab repo as an HTTP Backend!

Get your GitLab project ID : Settings → General → Project ID

Then we need to create a user access token or a project token, depending on your gitlab instance. Settings → Access Token → Add new Token

The Token needs to have at least the Maintainer role and the api scope

Finally, specify your Project ID and Token information in your provider.tf file

Example for a Project ID 6576578493

  backend "http" {
    address        = "https://gitlab.com/api/v4/projects/6576578493/terraform/state/tfstate"
    lock_address   = "https://gitlab.com/api/v4/projects/6576578493/terraform/state/tfstate/lock"
    unlock_address = "https://gitlab.com/api/v4/projects/6576578493/terraform/state/tfstate/lock"
    lock_method    = "POST"
    unlock_method  = "DELETE"
    username       = "tfstate_access"
    password       = "glpat-VMB1DHzAssssswZSTySSxe6a"
  }
0
Subscribe to my newsletter

Read articles from Fabrice Carrel directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Fabrice Carrel
Fabrice Carrel