Skip to content

Commit

Permalink
Merge pull request #8 from coveo/json_query_data_source
Browse files Browse the repository at this point in the history
Add a json_query data source
  • Loading branch information
julienduchesne authored Jul 4, 2018
2 parents b88db83 + 1304cb6 commit f7d952f
Show file tree
Hide file tree
Showing 12 changed files with 2,898 additions and 1 deletion.
41 changes: 41 additions & 0 deletions data_source_quantum_query_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"

"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/tidwall/gjson"
)

func dataSourceQuantumQueryJSON() *schema.Resource {
return &schema.Resource{
Read: dataSourceQuantumQueryJSONRead,

Schema: map[string]*schema.Schema{
"json": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"query": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"result": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceQuantumQueryJSONRead(d *schema.ResourceData, m interface{}) error {
json := d.Get("json").(string)
query := d.Get("query").(string)
queryResult := gjson.Get(json, query)

d.SetId(fmt.Sprintf("%d-%d", hashcode.String(json), hashcode.String(query)))
d.Set("result", queryResult.String())

return nil
}
2 changes: 1 addition & 1 deletion provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func main() {
ProviderFunc: func() terraform.ResourceProvider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
"quantum_query_json": dataSourceQuantumQueryJSON(),
"quantum_list_files": dataSourceQuantumListFiles(),
// "quantum_password": dataSourceQuantumPassword(),
},
ResourcesMap: map[string]*schema.Resource{
"quantum_password": resourceQuantumPassword(),
Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/tidwall/gjson/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f7d952f

Please sign in to comment.