Issue
I have a bash script , instance_status.sh which have all the access permission , this script is placed in / , when i try to execute it throws below error
Error: failed to execute "bash": bash: ./instance_status.sh: No such file or directory
on main.tf line 38, in data "external" "instance_status":
38: data "external" "instance_status" {
Bash Script :
#!/bin/bash
set -e
eval "$(jq -r '@sh "INSTANCE_ID=\(.id)"')"
sleep 360
status=$(aws ec2 describe-instance-status --instance-ids ${INSTANCE_ID} --output json --query
'InstanceStatuses[0]')
instance_status=$(echo ${status} | jq -r '.InstanceStatus.Details[0].Status')
system_status=$(echo ${status} | jq -r '.SystemStatus.Details[0].Status')
jq -n --arg inst_status "$instance_status" \
--arg sys_status "$system_status" \
'{"instance_status":$inst_status,"system_status":$sys_status}'
I am calling bash script from below terrafrom main.tf file :
data "external" "instance_status" {
program = ["bash", "${path.module}/instance_status.sh"]
query = {
id = aws_instance.QA-server-via-ami.id
}
}
output "test" {
value = data.external.instance_status.result
}
Could you please assist .
Solution
"this script is placed in /" so use absolute path:
/instance_status.sh
Answered By - user3461122