Terraform external data source result

I am trying Terraform External data source to get a response.
shell script returns the result in command line. Terraform apply does not return the result. it only returns resultid = “”

data "external" "get_inst_id" {
  program = ["bash", "shscripts/demo.sh"]

output "resultid" {
  value = data.external.get_inst_id.result.id

sh script:
aws ec2 describe-instances --region us-west-1 > inst.json
val=$(jq -r '.Instances[] | select(.Tags[].Value | contains("demo")).InstanceId' inst.json)
jq -n --arg iid "$val" '{id: $iid}' )

Terraform is functioning as expected, since your sh script does not emit anything on stdout. (Hint: test it!)

It does I ran in the command line.

The script you pasted contains a syntax error - an extra trailing ).

If I remove that, and replace the logic calling AWS with a simple


for ease of testing without dependencies, it works fine for me.

sorry. that’s a typo ignore it. I do not have an extra ) in my code.