File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -880,22 +880,27 @@ function common::export_provided_env_vars {
880880}
881881
882882# ######################################################################
883- # Check if the installed Terragrunt version is >=0.78.0 or not
883+ # Check if the given Terragrunt binary's version is >=0.78.0 or not
884884#
885885# This function helps to determine which terragrunt subcomand to use
886886# based on Terragrunt version
887887#
888+ # Arguments:
889+ # tool_path (string) resolved path to the terragrunt binary to check
890+ # (the actually resolved/pinned binary, NOT whatever's on $PATH -
891+ # those can differ once --tool-version is in play)
888892# Returns:
889893# - 0 if version >= 0.78.0
890894# - 1 if version < 0.78.0
891895# Defaults to 0 if version cannot be determined
892896# ######################################################################
893897# TODO: Drop after May 2027. Two years to upgrade is more than enough.
894898function common::terragrunt_version_ge_0.78 {
899+ local -r tool_path=" $1 "
895900 local terragrunt_version
896901
897902 # Extract version number (e.g., "terragrunt version v0.80.4" -> "0.80")
898- terragrunt_version=$( terragrunt --version 2> /dev/null | grep -oE ' [0-9]+\.[0-9]+' )
903+ terragrunt_version=$( " $tool_path " --version 2> /dev/null | grep -oE ' [0-9]+\.[0-9]+' )
899904 # If we can't parse version, default to newer command
900905 [[ ! $terragrunt_version ]] && return 0
901906
Original file line number Diff line number Diff line change @@ -14,14 +14,21 @@ function main {
1414 common::parse_and_export_env_vars
1515 # JFYI: `terragrunt hcl format` color already suppressed via PRE_COMMIT_COLOR=never
1616
17- if common::terragrunt_version_ge_0.78; then
17+ local -r tool_name=" terragrunt"
18+ # Needed early to pick the correct CLI syntax below against the actually
19+ # resolved/pinned terragrunt binary, not whatever's on $PATH.
20+ # common::per_dir_hook resolves it again for the per-dir runs.
21+ local -r tool_version=$( common::get_hook_config_value " --tool-version" )
22+ local tool_path
23+ tool_path=$( common::resolve_tool_path " $tool_name " " $tool_version " ) || exit $?
24+ readonly tool_path
25+
26+ if common::terragrunt_version_ge_0.78 " $tool_path " ; then
1827 local -ra SUBCOMMAND=(hcl format)
1928 else
2029 local -ra SUBCOMMAND=(hclfmt)
2130 fi
2231
23- local -r tool_name=" terragrunt"
24-
2532 # shellcheck disable=SC2153 # False positive
2633 common::per_dir_hook " $HOOK_ID " " $tool_name " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
2734}
Original file line number Diff line number Diff line change @@ -14,16 +14,23 @@ function main {
1414 common::parse_and_export_env_vars
1515 # JFYI: terragrunt providers lock color already suppressed via PRE_COMMIT_COLOR=never
1616
17- if common::terragrunt_version_ge_0.78; then
17+ local -r tool_name=" terragrunt"
18+ # Needed early to pick the correct CLI syntax below against the actually
19+ # resolved/pinned terragrunt binary, not whatever's on $PATH.
20+ # common::per_dir_hook resolves it again for the per-dir runs.
21+ local -r tool_version=$( common::get_hook_config_value " --tool-version" )
22+ local tool_path
23+ tool_path=$( common::resolve_tool_path " $tool_name " " $tool_version " ) || exit $?
24+ readonly tool_path
25+
26+ if common::terragrunt_version_ge_0.78 " $tool_path " ; then
1827 local -ra SUBCOMMAND=(run -- providers lock)
1928 local -ra RUN_ALL_SUBCOMMAND=(run --all -- providers lock)
2029 else
2130 local -ra SUBCOMMAND=(providers lock)
2231 local -ra RUN_ALL_SUBCOMMAND=(run-all providers lock)
2332 fi
2433
25- local -r tool_name=" terragrunt"
26-
2734 # shellcheck disable=SC2153 # False positive
2835 common::per_dir_hook " $HOOK_ID " " $tool_name " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
2936}
Original file line number Diff line number Diff line change @@ -14,16 +14,23 @@ function main {
1414 common::parse_and_export_env_vars
1515 # JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
1616
17- if common::terragrunt_version_ge_0.78; then
17+ local -r tool_name=" terragrunt"
18+ # Needed early to pick the correct CLI syntax below against the actually
19+ # resolved/pinned terragrunt binary, not whatever's on $PATH.
20+ # common::per_dir_hook resolves it again for the per-dir runs.
21+ local -r tool_version=$( common::get_hook_config_value " --tool-version" )
22+ local tool_path
23+ tool_path=$( common::resolve_tool_path " $tool_name " " $tool_version " ) || exit $?
24+ readonly tool_path
25+
26+ if common::terragrunt_version_ge_0.78 " $tool_path " ; then
1827 local -ra SUBCOMMAND=(run -- validate)
1928 local -ra RUN_ALL_SUBCOMMAND=(run --all -- validate)
2029 else
2130 local -ra SUBCOMMAND=(validate)
2231 local -ra RUN_ALL_SUBCOMMAND=(run-all validate)
2332 fi
2433
25- local -r tool_name=" terragrunt"
26-
2734 # shellcheck disable=SC2153 # False positive
2835 common::per_dir_hook " $HOOK_ID " " $tool_name " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
2936}
Original file line number Diff line number Diff line change @@ -14,16 +14,23 @@ function main {
1414 common::parse_and_export_env_vars
1515 # JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
1616
17- if common::terragrunt_version_ge_0.78; then
17+ local -r tool_name=" terragrunt"
18+ # Needed early to pick the correct CLI syntax below against the actually
19+ # resolved/pinned terragrunt binary, not whatever's on $PATH.
20+ # common::per_dir_hook resolves it again for the per-dir runs.
21+ local -r tool_version=$( common::get_hook_config_value " --tool-version" )
22+ local tool_path
23+ tool_path=$( common::resolve_tool_path " $tool_name " " $tool_version " ) || exit $?
24+ readonly tool_path
25+
26+ if common::terragrunt_version_ge_0.78 " $tool_path " ; then
1827 local -ra SUBCOMMAND=(hcl validate --inputs)
1928 local -ra RUN_ALL_SUBCOMMAND=(run --all hcl validate --inputs)
2029 else
2130 local -ra SUBCOMMAND=(validate-inputs)
2231 local -ra RUN_ALL_SUBCOMMAND=(run-all validate-inputs)
2332 fi
2433
25- local -r tool_name=" terragrunt"
26-
2734 # shellcheck disable=SC2153 # False positive
2835 common::per_dir_hook " $HOOK_ID " " $tool_name " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
2936}
You can’t perform that action at this time.
0 commit comments