0

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 .

4
  • Why do you use bash to launch a script? I always use sh, and let the first line in the script (#!/bin/bash) decide which shell to use. Commented Apr 15, 2021 at 14:06
  • @Dominique, if you use sh myscript, then the shebang line is just a comment, and your script is run with the "sh" interpreter. To really use the shebang line, you must let the OS handle the script: chmod a+x myscript; ./myscript -- see your system's execve man page. Commented Apr 15, 2021 at 14:39
  • @antik, what's in ${path.module}? Apparently "instance_status.sh" is not there. Commented Apr 15, 2021 at 14:41
  • If the script is in /, you must call it like this /instance_status.sh. If you call it with ./instance_status.sh, it is trying to find the script in the current directory, described by .. Commented Apr 16, 2021 at 1:45

1 Answer 1

1

"this script is placed in /" so use absolute path:

/instance_status.sh
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.