3

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:

  1. Create a dedicated git repo
  2. 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.
  3. 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

1

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!

1
  • Thanks, the github project is useful. As for the github issue on the HashiCorp Terraform project, they've closed it, not sure why it wasn't pursued. – Haneef Ibn Ahmad Aug 30 '20 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.