-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hi,
I am having trouble debugging an external data source error using terragrunt.
The first problem is that terragrunt moves and executes the scripts in a temporary directory, so I cannot reference other scripts using relative paths. This was hard to debug already, but now I am trying to use absolute paths - with the caveat that I need them to run both locally and on github actions.
My main.tf
file contains the following:
data "external" "container_sha" {
program = [
"bash", "./get_container_sha.sh",
"${local.artifact_registry_path}",
"${var.container_tag}"
]
}
locals {
container_sha = data.external.container_sha.result["container_sha"]
}
While the get_container_sha.sh
script contains the following:
if [[ -v GITHUB_WORKSPACE ]]; then
ROOT="${GITHUB_WORKSPACE}";
elif [[ -v WORKSPACE ]]; then
ROOT="${WORKSPACE}";
else
echo "Unable to find repo root" && exit 1;
fi
echo $("${ROOT}/src/mypath/get_container_sha.sh" "$1" "$2")
So the local script is just a way to compute the absolute path of the real script, passing the right arguments.
Anyway - everything works fine locally - terragrunt plan & apply
all work fine, find the scripts, return the correct results, etc.
On github actions, the external data source breaks in a way that's impossible to debug - there is virtually no information given, simply 'script didn't work'. The output is not printed anywhere at any log level.
My github actions file:
- name: temporary
run: src/modules/cloud-run/get_container_sha.sh repo tag # <--- This works correctly!!
- name: Call terragrunt apply
uses: gruntwork-io/terragrunt-action@v2
env:
GOOGLE_OAUTH_ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}
with:
tf_version: "1.10.0"
tg_version: "0.69.13"
tg_dir: 'src/prod/cloud-run'
tg_command: 'apply --terragrunt-log-level trace --terragrunt-debug'
The error message (see below) only says that something went wrong, but I cannot figure out what. How can I debug the script execution to understand what went wrong?
Calling the script by itself in a separate stage works fine and returns the correct results, it only breaks when terragrunt runs it (on github actions - it also works fine locally). I need to debug it from terragrunt perspective - but how?
Error message:
11:46:38.437 STDOUT terraform: data.external.container_sha: Reading...
11:46:38.666 STDERR terraform: ╷
11:46:38.666 STDERR terraform: │ Error: Unexpected External Program Results
11:46:38.666 STDERR terraform: │
11:46:38.666 STDERR terraform: │ with data.external.container_sha,
11:46:38.666 STDERR terraform: │ on main.tf line 19, in data "external" "container_sha":
11:46:38.666 STDERR terraform: │ 19: program = [
11:46:38.666 STDERR terraform: │ 20: "bash", "./get_container_sha.sh",
11:46:38.666 STDERR terraform: │ 21: "${local.artifact_registry_path}",
11:46:38.666 STDERR terraform: │ 22: "${var.container_tag}"
11:46:38.667 STDERR terraform: │ 23: ]
11:46:38.667 STDERR terraform: │
11:46:38.667 STDERR terraform: │ The data source received unexpected results after executing the program.
11:46:38.667 STDERR terraform: │
11:46:38.667 STDERR terraform: │ Program output must be a JSON encoded map of string keys and string values.
11:46:38.667 STDERR terraform: │
11:46:38.667 STDERR terraform: │ If the error is unclear, the output can be viewed by enabling Terraform's
11:46:38.667 STDERR terraform: │ logging at TRACE level. Terraform documentation on logging:
11:46:38.667 STDERR terraform: │ https://www.terraform.io/internals/debugging
11:46:38.667 STDERR terraform: │
11:46:38.667 STDERR terraform: │ Program: /usr/bin/bash
11:46:38.667 STDERR terraform: │ Result Error: unexpected end of JSON input
11:46:38.667 STDERR terraform: ╵