terraform-provider-gitinfo

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 3 Imported by: 0

README

terraform-provider-gitinfo

Use Git context (current branch name and SHA) in Terraform scripts.

Use Case

We store Terraform module files in the same repo as our code. CI builds a package (for instance, a docker image) from a commit and tags it with the git SHA. When the master Terraform script applies the module, it builds a deployment specifying the docker image using the module SHA. In order to do that, we use terraform-provider-gitinfo to get easy access to the git SHA.

Terraform Example

provider "gitinfo" {}

data "gitinfo_repo" "root" {
  path = "${path.root}"
  # In a module you would use "${path.module}"
}

Once this data resource is defined, you can use any of the following

  "${data.gitinfo_repo.root.branch_full}"   # refs/heads/master
  "${data.gitinfo_repo.root.branch_short}"  # master
  "${data.gitinfo_repo.root.sha_full}"      # f78a498022d81d5b933ab68801f0b4387aa197d5
  "${data.gitinfo_repo.root.sha_short}"     # f78a498

Installation

  • Download terraform-provider-gitinfo binary from Github
  • Unzip the zip file
  • Move terraform-provider-gitinfo binary to $HOME/.terraform.d/plugins directory
mkdir -p $HOME/.terraform.d/plugins
mv terraform-provider-gitinfo $HOME/.terraform.d/plugins/terraform-provider-gitinfo
  • Run terraform init in your terraform project
terraform init

Credits

This code based on Matthias Bartelmeß's https://github.com/fourplusone/terraform-provider-git. (I didn't simply fork because terraform-provider-git because it serves a different purpose. That one is about committing files to a configured repo. This provider provides information without knowing a remote repo URL.)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL