Skip to content

Initialise GitLab-backed remote Terraform state for local Terraform or OpenTofu CLIs

Problem to solve

There is a repeating sequence of manual steps, which one needs to follow to activate a remote Terraform state for local Terraform or OpenTofu CLIs:

  1. Go to the Terraform state page and copy the provided command.
  2. Replace the GITLAB_ACCESS_TOKEN with your PAT and maybe set a TF_STATE_NAME
  3. (Optional) Replace terraform with tofu.

The last step should be recommended, since GitLab is moving towards that direction. gitlab#524144

Proposal

The glab CLI eventually already owns its own valid token, which it could lend to Terraform when initialised through it.

It could also help with selecting a desired state name.

Yet especially being able to choose to favour OpenTofu for this flow removes possible barriers in environments that were not yet locked into the Terraform ecosystem.

Further details

Everything is already there, we just need to collect it.

Links / references

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information