You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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}";elseecho"Unable to find repo root"&&exit 1;fiecho$("${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: temporaryrun: src/modules/cloud-run/get_container_sha.sh repo tag # <--- This works correctly!!
- name: Call terragrunt applyuses: gruntwork-io/terragrunt-action@v2env:
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's11:46:38.667 STDERR terraform: │ logging at TRACE level. Terraform documentation on logging:11:46:38.667 STDERR terraform: │ https://www.terraform.io/internals/debugging11:46:38.667 STDERR terraform: │ 11:46:38.667 STDERR terraform: │ Program: /usr/bin/bash11:46:38.667 STDERR terraform: │ Result Error: unexpected end of JSON input11:46:38.667 STDERR terraform: ╵
The text was updated successfully, but these errors were encountered:
They're designed to help you work out paths consistently when using Terragrunt, regardless of where you're using it.
The error that you're getting is coming from Terraform, not Terragrunt, which is why you might be having trouble troubleshooting it.
For what it's worth, you don't need to use a data "external" to get your container sha when working with Terragrunt.
You can resolve it with run_cmd, then pass it in as an input. I personally find it easier to reason about what's going on when I don't use things like data "external" in my .tf code, but you might prefer it this way.
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:While the
get_container_sha.sh
script contains the following: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:
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:
The text was updated successfully, but these errors were encountered: