HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Dedicated/Separate Git Repo as Terraform Remote Backend

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
backendseparatededicatedrepogitremoteterraform

Problem

I see that there are multiple options for Backends, however git isn’t one of them.

I believe git can be used as a backend for tfstate, in the below steps:

  • Create a dedicated git repo



  • Commit the tfstate files in a specified directory and branch. Only fetch the required files, rather than the whole repo, as this repo could be used to store multiple tfstate files on different directories.



  • For locking and unlocking:


Method 1 (git LFS): use ‘git lfs lock’

Method 2 (git - where lfs isn’t possible): Use another file suffixed with .lock, which should contain the lock state.

Is there any plan for Terraform to release git as a backend?

I've also thought of ways to use the HTTP backend to upload to a git, no luck yet.

Thoughts on how this can be achieved?

There's already a Github/Gitlab/Bitbucket provider.

Thanks,

Note: Also asked in the Terraform Discuss

Solution

Using git for terraform remote state management is an interesting, but non-standard implementation. Storing binary / large files in git, integrating a locking system and a few other concerns come to mind. Using s3, Buckets or other storage options provide the multiple statefile management (versions in buckets, folders in buckets or terraform folder structure / workspaces) and other functionality you mentioned.

If you would like to pursue using git for remote state management, check out the community project terraform-backend-git. There is also a good discussion around it in the terraform issues section: https://github.com/hashicorp/terraform/issues/16616.

If you attempt to use the tool from the community, it would be great to hear about your experience. Good luck!

Context

StackExchange DevOps Q#12206, answer score: 1

Revisions (0)

No revisions yet.