Created
June 30, 2021 21:14
-
-
Save alexlopes/bb9d3553d93e38e2865be8c768f16c1e to your computer and use it in GitHub Desktop.
Revisions
-
alexlopes created this gist
Jun 30, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ ### Returns a JSON result for External Data Sourcce ```hcl data "external" "generate_secret" { program = ["bash", "${path.module}/get-name.sh"] query = { my_name = "John" my_middle_name = "Doe" } } # get-name.sh function output_json(){ # the stdin for external datasource is a JSON object eval "$(jq -r '@sh "NAME=\(.my_name) MIDDLE_NAME=\(.my_middle_name)"')" # some logic jq -n \ --arg name "${NAME}" \ --arg mid_name "${MIDDLE_NAME}" \ '{"name":$name, "middle_name":$mid_name}' } ```