https://github.com/massdriver-cloud/terraform-provider-jq
https://github.com/massdriver-cloud/terraform-provider-jq
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/massdriver-cloud/terraform-provider-jq
- Owner: massdriver-cloud
- License: apache-2.0
- Created: 2022-02-26T20:54:26.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-17T04:44:08.000Z (almost 4 years ago)
- Last Synced: 2023-03-04T01:08:43.066Z (over 3 years ago)
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 10
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraform Provider for jq
This plugin brings the power of [jq](https://stedolan.github.io/jq/) to Terraform, allowing you to parse and extract complex data from JSON or even HCL objects.
## Usage
No initialiation is required, you can begin using the provider immediately.
```hcl
data "jq_query" "example" {
data = "{\"a\": \"b\"}"
query = ".a"
}
output "example" {
value = data.jq_query.example.result
}
```
This will output:
```
Outputs:
example = "\"b\""
```
### HCL Compatibility
The jq operates on json formatted strings. Fortunately, terraform provides the `jsonencode()` and `jsondecode()` functions for easily converting back and forth between HCL and json strings.
The above example in pure HCL:
```hcl
data "jq_query" "example" {
data = jsonencode({a = "b"})
query = ".a"
}
output "example" {
value = jsondecode(data.jq_query.example.result)
}
```
This will output:
```
Outputs:
example = "b"
```
### Multiple Results
Some jq queries will produce multiple elements. In this case, the result will have multiple lines, with each line containing an element as a JSON encoded string. Keep in mind this means that the result **cannot** be converted to HCL with `jsondecode()` as the string itself is not valid JSON.
```hcl
data "jq_query" "example" {
data = jsonencode([{id:1},{id:2},{id:3}])
query = ".[] | .id"
}
output "example" {
value = data.jq_query.example.result
}
```
This will output:
```sh
Outputs:
example = <