Skip to content

Commit

Permalink
Group output formats in README closer
Browse files Browse the repository at this point in the history
  • Loading branch information
shihanng committed Nov 26, 2021
1 parent 0828949 commit 67fca7e
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,41 @@ variable "docker_ports" {
docker_ports = null
image_id = null
```
- **tfvar** also provides output in environment variable formats:
- **tfvar** also provides other output formats:
- In environment variable formats with `-e` flag:
```
$ tfvar . -e
export TF_VAR_availability_zone_names='["us-west-1a"]'
export TF_VAR_docker_ports='[{ external = 8300, internal = 8300, protocol = "tcp" }]'
export TF_VAR_image_id=''
```
- The `-r, --resource` flag outputs all variables as `tfe_variable`
Terraform resource of [Terraform Enterprise (tfe) provider](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/variable).
- The `-w, --workspace` flag outputs all variables in the payload format for the API
<https://www.terraform.io/docs/cloud/api/workspace-variables.html#sample-payload>.
which can used together with `jq` to filter variables by key name.
```
$ tfvar -w . | jq '. | select(.data.attributes.key == "region")'
{
"data": {
"type": "vars",
"attributes": {
"key": "region",
"value": "",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
}
}
```
- 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.
```
$ export TF_VAR_availability_zone_names='["custom_zone"]'
Expand Down Expand Up @@ -96,18 +124,6 @@ variable "docker_ports" {
image_id = "abc"
```

- The `-r, --resource` flag outputs all variables as terraform resources for the `tfe_variable resource` found in the `tfe` provider <https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/variable>

- The `-w, --workspace` flag outputs all variables in the payload format for the API <https://www.terraform.io/docs/cloud/api/workspace-variables.html#sample-payload>. You can use `jq` to filter variables by key name.
```
$ tfvar -w . | jq '. | select(.data.attributes.key == "region")'
{
"data": {
...
}
}
```
For more info, checkout the `--help` page:

```
Expand Down

0 comments on commit 67fca7e

Please sign in to comment.