{"id":13505886,"url":"https://github.com/shihanng/tfvar","last_synced_at":"2025-04-12T23:32:50.502Z","repository":{"id":42527029,"uuid":"235794044","full_name":"shihanng/tfvar","owner":"shihanng","description":"Terraform's variable definitions template generator.","archived":false,"fork":false,"pushed_at":"2024-11-18T23:45:58.000Z","size":5341,"stargazers_count":216,"open_issues_count":4,"forks_count":23,"subscribers_count":5,"default_branch":"trunk","last_synced_at":"2025-04-04T02:46:38.467Z","etag":null,"topics":["cli","go","golang","hcl","terraform","terraform-configurations","terraform-templates","terraform-variables","tfvar","tfvars"],"latest_commit_sha":null,"homepage":"https://dev.to/shihanng/tfvar-a-tool-to-help-you-write-terraform-s-variable-definitions-1j65","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shihanng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-23T12:50:22.000Z","updated_at":"2025-02-14T12:34:50.000Z","dependencies_parsed_at":"2022-09-26T17:50:55.578Z","dependency_job_id":"88fbb0fe-939e-4f43-8d82-2d1ee4901890","html_url":"https://github.com/shihanng/tfvar","commit_stats":{"total_commits":125,"total_committers":9,"mean_commits":13.88888888888889,"dds":0.248,"last_synced_commit":"1d3cacbbee4256578450894c1578ba7bc8100716"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shihanng%2Ftfvar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shihanng%2Ftfvar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shihanng%2Ftfvar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shihanng%2Ftfvar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shihanng","download_url":"https://codeload.github.com/shihanng/tfvar/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","go","golang","hcl","terraform","terraform-configurations","terraform-templates","terraform-variables","tfvar","tfvars"],"created_at":"2024-08-01T00:01:16.257Z","updated_at":"2025-04-12T23:32:50.483Z","avatar_url":"https://github.com/shihanng.png","language":"Go","funding_links":[],"categories":["Tools","cli","Go"],"sub_categories":["Community providers"],"readme":"# `tfvar`\n\n[![](https://github.com/shihanng/tfvar/workflows/main/badge.svg?branch=trunk)](https://github.com/shihanng/tfvar/actions?query=workflow%3Amain)\n[![](https://github.com/shihanng/tfvar/workflows/release/badge.svg?branch=trunk)](https://github.com/shihanng/tfvar/actions?query=workflow%3Arelease)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/shihanng/tfvar)](https://github.com/shihanng/tfvar/releases)\n[![Coverage Status](https://coveralls.io/repos/github/shihanng/tfvar/badge.svg?branch=trunk)](https://coveralls.io/github/shihanng/tfvar?branch=trunk)\n[![Go Report Card](https://goreportcard.com/badge/github.com/shihanng/tfvar)](https://goreportcard.com/report/github.com/shihanng/tfvar)\n[![Package Documentation](https://godoc.org/github.com/shihanng/tfvar/pkg/tfvar?status.svg)](http://godoc.org/github.com/shihanng/tfvar/pkg/tfvar)\n[![GitHub license](https://img.shields.io/github/license/shihanng/tfvar)](https://github.com/shihanng/tfvar/blob/trunk/LICENSE)\n\n![Banner of the project](./banner.png)\n\n**tfvar** is a [Terraform](https://www.terraform.io/)'s [variable definitions](https://www.terraform.io/docs/configuration/variables.html#assigning-values-to-root-module-variables) 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.\n\nFor Terraform configuration that has input variables declared, e.g.,\n\n```terraform\nvariable \"image_id\" {\n  type = string\n}\n\nvariable \"availability_zone_names\" {\n  type    = list(string)\n  default = [\"us-west-1a\"]\n}\n\nvariable \"docker_ports\" {\n  type = list(object({\n    internal = number\n    external = number\n    protocol = string\n  }))\n  default = [\n    {\n      internal = 8300\n      external = 8300\n      protocol = \"tcp\"\n    }\n  ]\n}\n```\n\n- **tfvar** will search for all input variables and generate template that helps user populates those variables easily:\n    ```\n    $ tfvar .\n    availability_zone_names = [\"us-west-1a\"]\n    docker_ports            = [{ external = 8300, internal = 8300, protocol = \"tcp\" }]\n    image_id                = null\n    ```\n- Note that default values are assigned to the definitions by default as shown above. Use the `--ignore-default` options to ignore the default values.\n    ```\n    $ tfvar . --ignore-default\n    availability_zone_names = null\n    docker_ports            = null\n    image_id                = null\n    ```\n- **tfvar** also provides other output formats:\n\n  - In environment variable formats with `-e` flag:\n\n    ```\n    $ tfvar . -e\n    export TF_VAR_availability_zone_names='[\"us-west-1a\"]'\n    export TF_VAR_docker_ports='[{ external = 8300, internal = 8300, protocol = \"tcp\" }]'\n    export TF_VAR_image_id=''\n    ```\n\n  - The `-r, --resource` flag outputs all variables as `tfe_variable`\n    resource of [Terraform Enterprise (tfe) provider](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/variable).\n\n  - The `-w, --workspace` flag outputs all variables in the payload format for the\n    [Workspace Variables API](https://www.terraform.io/docs/cloud/api/workspace-variables.html#sample-payload)\n    \u003chttps://www.terraform.io/docs/cloud/api/workspace-variables.html#sample-payload\u003e\n    which can used together with `jq` to filter variables by key name.\n\n    ```\n    $ tfvar -w . | jq '. | select(.data.attributes.key == \"region\")'\n    {\n      \"data\": {\n        \"type\": \"vars\",\n        \"attributes\": {\n          \"key\": \"region\",\n          \"value\": \"\",\n          \"description\": \"\",\n          \"category\": \"terraform\",\n          \"hcl\": false,\n          \"sensitive\": false\n        }\n      }\n    }\n    ```\n\n- There is also `--auto-assign` option for those who wants the values from `terraform.tfvars[.json]`, `*.auto.tfvars[.json]`, and environment variables (`TF_VAR_` followed by the name of a declared variable) to be assigned to the generated definitions automatically.\n    ```\n    $ export TF_VAR_availability_zone_names='[\"custom_zone\"]'\n    $ tfvar . --auto-assign\n    availability_zone_names = [\"custom_zone\"]\n    docker_ports            = [{ external = 8300, internal = 8300, protocol = \"tcp\" }]\n    image_id                = null\n    ```\n- Like the [`terraform (plan|apply)`](https://www.terraform.io/docs/configuration/variables.html#variables-on-the-command-line) CLI tool, individual vairables can also be specified via `--var` option.\n    ```\n    $ tfvar . --var=availability_zone_names='[\"custom_zone\"]' --var=image_id=abc123\n    availability_zone_names = [\"custom_zone\"]\n    docker_ports            = [{ external = 8300, internal = 8300, protocol = \"tcp\" }]\n    image_id                = \"abc123\"\n    ```\n- Variables in file can also be specified via `--var-file` option.\n    ```\n    $ cat my.tfvars\n    image_id = \"xyz\"\n    $ tfvar . --var-file my.tfvars\n    availability_zone_names = [\"us-west-1a\"]\n    docker_ports            = [{ external = 8300, internal = 8300, protocol = \"tcp\" }]\n    image_id                = \"xyz\"\n    ```\n\n- Multiple files can be specified via providing more `--var-file` options, variables overrides as for `terraform` command.\n    ```\n    $ cat my.tfvars\n    image_id = \"xyz\"\n\n    $ cat other.tfvars\n    image_id = \"abc\"\n\n    $ tfvar . --var-file my.tfvars --var-file other.tfvars\n    image_id = \"abc\"\n  ```\n\nFor more info, checkout the `--help` page:\n\n```\n$ tfvar --help\nGenerate variable definitions template for Terraform module as\none would write it in variable definitions files (.tfvars).\n\nUsage:\n  tfvar [DIR] [flags]\n\nFlags:\n  -a, --auto-assign            Use values from environment variables TF_VAR_* and\n                               variable definitions files e.g. terraform.tfvars[.json] *.auto.tfvars[.json]\n  -d, --debug                  Print debug log on stderr\n  -e, --env-var                Print output in export TF_VAR_image_id=ami-abc123 format\n  -h, --help                   help for tfvar\n      --ignore-default         Do not use defined default values\n  -r, --resource               Print output in Terraform Enterprise (tfe) provider's tfe_variable resource format\n      --var stringArray        Set a variable in the generated definitions.\n                               This flag can be set multiple times.\n      --var-file stringArray   Set variables from a file.\n                               This flag can be set multiple times.\n  -v, --version                version for tfvar\n  -w, --workspace              Print output variables as payloads for Workspace Variables API\n```\n\n\n## Installation\n\n### [Homebrew (macOS)](https://github.com/shihanng/homebrew-tfvar)\n\n```\nbrew install shihanng/tfvar/tfvar\n```\n\n### [MacPorts (macOS)](https://ports.macports.org/port/tfvar/)\n\n```\nsudo port install tfvar\n```\n\n### Debian, Ubuntu\n\n```\ncurl -sLO https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.deb\ndpkg -i tfvar_linux_amd64.deb\n```\n\n### RedHat, CentOS\n\n```\nrpm -ivh https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.rpm\n```\n\n### Binaries\n\nThe [release page](https://github.com/shihanng/tfvar/releases) 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`:\n\n```\ncurl -sL https://github.com/shihanng/tfvar/releases/latest/download/tfvar_linux_amd64.tar.gz | \\\n    tar xz -C /usr/local/bin/ tfvar\n```\n\n### For Gophers\n\nWith [Go](https://golang.org/doc/install) already installed in your system, use `go get`\n\n```\ngo get github.com/shihanng/tfvar\n```\n\nor clone this repo and `make install`\n\n```\ngit clone https://github.com/shihanng/tfvar.git\ncd tfvar\nmake install\n```\n\n## Contributing\n\nWant 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:.\n\n```\nmake lint\nmake test\n```\n\nshould help with the idiomatic Go styles and unit-tests.\n\n## License\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshihanng%2Ftfvar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshihanng%2Ftfvar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshihanng%2Ftfvar/lists"}