Hi ,
I am facing difficulty in fetching a key’s value which is stored as a json in a file in s3
data "aws_s3_bucket_object" "json_values" {
bucket = "sasmpdle-adp-dummy-bukkctt-soudtheast-2-473689e8e"
key = "test.txt"
}
data "external" "bash" {
program = ["bash","script.sh","name"]
query = {
body = data.aws_s3_bucket_object.json_values.body
}
}
output "data" {
value = data.aws_s3_bucket_object.json_values.body
}
output "yourname" {
value= data.external.bash.result.output
}
The contents of test.txt is
{"name":"arjun","sirname":"dandagi" ,"address":{ "post":"haveri", "pin":"581120"}}
script.sh is
#!/bin/bash
key=$1
function error_exit() {
echo "$1" 1>&2
exit 1
}
function check_deps() {
test -f $(which jq) || error_exit "jq command not detected in path, please install it"
}
function parse_input() {
read data
output=$( { echo "$data" | jq -r '.body | fromjson' | jq -r --arg v "$key" '.[$v]'} || echo "failed" && exit 1 )
jq -n --arg output "$output" '{"output":$output}'
}
check_deps
parse_input
however i am not seeing expected result in the outuput
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
data = {“name”:“arjun”,“sirname”:“dandagi” ,“address”:{ “post”:“chikkabasur”, “pin”:“581120”}}
yourname =
. yourname is always returned empty. can you help me if there is any mistake in my script . it worked fine when i ran separately. not sure how the query is passed with value that itself is a json