Skip to content

Instantly share code, notes, and snippets.

@alexlopes
Created June 30, 2021 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlopes/bb9d3553d93e38e2865be8c768f16c1e to your computer and use it in GitHub Desktop.
Save alexlopes/bb9d3553d93e38e2865be8c768f16c1e to your computer and use it in GitHub Desktop.
Terraform Tricks

Returns a JSON result for External Data Sourcce

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}' 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment