Home

Awesome

tfvar

GitHub release (latest by date) Coverage Status Go Report Card Package Documentation GitHub license

Banner of the project

tfvar is a Terraform's variable definitions template generator. It scans your Terraform configurations or modules and extracts the variables into formats of your choice for editing, e.g., tfvar, environment variables, etc.

For Terraform configuration that has input variables declared, e.g.,

variable "image_id" {
  type = string
}

variable "availability_zone_names" {
  type    = list(string)
  default = ["us-west-1a"]
}

variable "docker_ports" {
  type = list(object({
    internal = number
    external = number
    protocol = string
  }))
  default = [
    {
      internal = 8300
      external = 8300
      protocol = "tcp"
    }
  ]
}

For more info, checkout the --help page:

$ tfvar --help
Generate variable definitions template for Terraform module as
one would write it in variable definitions files (.tfvars).

Usage:
  tfvar [DIR] [flags]

Flags:
  -a, --auto-assign            Use values from environment variables TF_VAR_* and
                               variable definitions files e.g. terraform.tfvars[.json] *.auto.tfvars[.json]
  -d, --debug                  Print debug log on stderr
  -e, --env-var                Print output in export TF_VAR_image_id=ami-abc123 format
  -h, --help                   help for tfvar
      --ignore-default         Do not use defined default values
  -r, --resource               Print output in Terraform Enterprise (tfe) provider's tfe_variable resource format
      --var stringArray        Set a variable in the generated definitions.
                               This flag can be set multiple times.
      --var-file stringArray   Set variables from a file.
                               This flag can be set multiple times.
  -v, --version                version for tfvar
  -w, --workspace              Print output variables as payloads for Workspace Variables API

Installation

Homebrew (macOS)

brew install shihanng/tfvar/tfvar

MacPorts (macOS)

sudo port install tfvar

Debian, Ubuntu

curl -sLO https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.deb
dpkg -i tfvar_linux_amd64.deb

RedHat, CentOS

rpm -ivh https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.rpm

Binaries

The release page contains binaries built for various platforms. Download the version matches your environment (e.g. linux_amd64) and place the binary in the executable $PATH e.g. /usr/local/bin:

curl -sL https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.tar.gz | \
    tar xz -C /usr/local/bin/ tfvar

For Gophers

With Go already installed in your system, use go get

go get github.com/shihanng/tfvar

or clone this repo and make install

git clone https://github.com/shihanng/tfvar.git
cd tfvar
make install

Contributing

Want to add missing feature? Found bug :bug:? Pull requests and issues are welcome. For major changes, please open an issue first to discuss what you would like to change :heart:.

make lint
make test

should help with the idiomatic Go styles and unit-tests.

License

MIT