Data "external" "git_hash"

Hi,

I have been facing below issue on executing terraform plan command.

Error: failed to execute “files/iac_git_info.sh”: fork/exec files/iac_git_info.sh: %1 is not a valid Win32 application.

on main.tf line 401, in data “external” “git_hash”:
401: data “external” “git_hash” {

Error: failed to execute “files/iac_tooling_version.sh”: fork/exec files/iac_tooling_version.sh: %1 is not a valid Win32 application.

on main.tf line 405, in data “external” “iac_tooling_version”:
405: data “external” “iac_tooling_version” {

Hi @raghudevendra,

From this error message it seems that you are using Terraform on a Windows system.

Windows doesn’t have built-in support for executing shell scripts, so to use this on Windows you will need to change the configuration to run a program that you Windows system knows how to run.

If you have a Unix shell like bash installed on your Windows system separately then you may be able to make this work by specifying that shell at the command to run and then passing the script filename as the argument to the shell.

If you don’t have a Unix shell then you may need to port your script into a form that Windows knows how to run, such as a .cmd script for the Windows Command Prompt.

Hi @apparentlymart

Now i have fixed the Unix shell bash issue on windows by giving bash as below.

data “external” “iac_tooling_version” {
program = [“bash”,“files/tools/iac_tooling_version.sh”]
}

Now i am getting below error on jq. I have installed jq 1.6 but still face error as below.

Error: failed to execute “bash”: jq command not detected in path, please install it…

with data.external.iac_tooling_version,
on main.tf line 259, in data “external” “iac_tooling_version”:
259: data “external” “iac_tooling_version” {

And this is my script

#!/usr/bin/env bash

We need to return an error if things don’t work

set -e

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…”
}

check_deps

TERRAFORM_INFO="(terraform version -json)" TERRAFORM_VERSION=(echo "TERRAFORM_INFO" | jq .terraform_version ) TERRAFORM_REVISION=(echo "TERRAFORM_INFO" | jq .terraform_revision ) PROVIDER_SELECTIONS=(echo "TERRAFORM_INFO" | jq -c .provider_selections ) TERRAFORM_OUTDATED=(echo “$TERRAFORM_INFO” | jq .terraform_outdated )

jq -n
–arg terraform_version “$TERRAFORM_VERSION”
–arg terraform_revision “$TERRAFORM_REVISION”
–arg terraform_outdated “$TERRAFORM_OUTDATED”
–arg provider_selections “$PROVIDER_SELECTIONS”
‘{“terraform_version”:$terraform_version, “terraform_revision”:$terraform_revision, “terraform_outdated”:$terraform_outdated, “provider_selections”:$provider_selections}’

echo “$(echo $TERRAFORM_INFO |jq -cr)”

The end!