File tree Expand file tree Collapse file tree 5 files changed +64
-7
lines changed Expand file tree Collapse file tree 5 files changed +64
-7
lines changed Original file line number Diff line number Diff line change @@ -606,3 +606,34 @@ function common::export_provided_env_vars {
606
606
export $var_name =" $var_value "
607
607
done
608
608
}
609
+
610
+ # ######################################################################
611
+ # Check if the installed Terragrunt version is >=0.78.0 or not
612
+ #
613
+ # This function helps to determine which terragrunt subcomand to use
614
+ # based on Terragrunt version
615
+ #
616
+ # Returns:
617
+ # - 0 if version >= 0.78.0
618
+ # - 1 if version < 0.78.0
619
+ # Defaults to 0 if version cannot be determined
620
+ # ######################################################################
621
+ # TODO: Drop after May 2027. Two years to upgrade is more than enough.
622
+ function common::terragrunt_version_ge_0.78 {
623
+ local terragrunt_version
624
+
625
+ # Extract version number (e.g., "terragrunt version v0.80.4" -> "0.80")
626
+ terragrunt_version=$( terragrunt --version 2> /dev/null | grep -oE ' [0-9]+\.[0-9]+' )
627
+ # If we can't parse version, default to newer command
628
+ [[ ! $terragrunt_version ]] && return 0
629
+
630
+ local major minor
631
+ IFS=' .' read -r major minor <<< " $terragrunt_version"
632
+
633
+ # New subcommands added in v0.78.0 (May 2025)
634
+ if [[ $major -gt 0 || ($major -eq 0 && $minor -ge 78) ]]; then
635
+ return 0
636
+ else
637
+ return 1
638
+ fi
639
+ }
Original file line number Diff line number Diff line change @@ -12,7 +12,13 @@ function main {
12
12
common::parse_cmdline " $@ "
13
13
common::export_provided_env_vars " ${ENV_VARS[@]} "
14
14
common::parse_and_export_env_vars
15
- # JFYI: terragrunt hclfmt color already suppressed via PRE_COMMIT_COLOR=never
15
+ # JFYI: `terragrunt hcl format` color already suppressed via PRE_COMMIT_COLOR=never
16
+
17
+ if common::terragrunt_version_ge_0.78; then
18
+ local -ra SUBCOMMAND=(hcl format)
19
+ else
20
+ local -ra SUBCOMMAND=(hclfmt)
21
+ fi
16
22
17
23
# shellcheck disable=SC2153 # False positive
18
24
common::per_dir_hook " $HOOK_ID " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
@@ -46,7 +52,7 @@ function per_dir_hook_unique_part {
46
52
local -a -r args=(" $@ " )
47
53
48
54
# pass the arguments to hook
49
- terragrunt hclfmt " ${args[@]} "
55
+ terragrunt " ${SUBCOMMAND[@]} " " ${args[@]} "
50
56
51
57
# return exit code to common::per_dir_hook
52
58
local exit_code=$?
@@ -63,7 +69,7 @@ function run_hook_on_whole_repo {
63
69
local -a -r args=(" $@ " )
64
70
65
71
# pass the arguments to hook
66
- terragrunt hclfmt " $( pwd) " " ${args[@]} "
72
+ terragrunt " ${SUBCOMMAND[@]} " " $( pwd) " " ${args[@]} "
67
73
68
74
# return exit code to common::per_dir_hook
69
75
local exit_code=$?
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ function main {
14
14
common::parse_and_export_env_vars
15
15
# JFYI: terragrunt providers lock color already suppressed via PRE_COMMIT_COLOR=never
16
16
17
+ if common::terragrunt_version_ge_0.78; then
18
+ local -ra RUN_ALL_SUBCOMMAND=(run --all providers lock)
19
+ else
20
+ local -ra RUN_ALL_SUBCOMMAND=(run-all providers lock)
21
+ fi
22
+
17
23
# shellcheck disable=SC2153 # False positive
18
24
common::per_dir_hook " $HOOK_ID " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
19
25
}
@@ -63,7 +69,7 @@ function run_hook_on_whole_repo {
63
69
local -a -r args=(" $@ " )
64
70
65
71
# pass the arguments to hook
66
- terragrunt run-all providers lock " ${args[@]} "
72
+ terragrunt " ${RUN_ALL_SUBCOMMAND[@]} " " ${args[@]} "
67
73
68
74
# return exit code to common::per_dir_hook
69
75
local exit_code=$?
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ function main {
14
14
common::parse_and_export_env_vars
15
15
# JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
16
16
17
+ if common::terragrunt_version_ge_0.78; then
18
+ local -ra RUN_ALL_SUBCOMMAND=(run --all validate)
19
+ else
20
+ local -ra RUN_ALL_SUBCOMMAND=(run-all validate)
21
+ fi
22
+
17
23
# shellcheck disable=SC2153 # False positive
18
24
common::per_dir_hook " $HOOK_ID " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
19
25
}
@@ -63,7 +69,7 @@ function run_hook_on_whole_repo {
63
69
local -a -r args=(" $@ " )
64
70
65
71
# pass the arguments to hook
66
- terragrunt run-all validate " ${args[@]} "
72
+ terragrunt " ${RUN_ALL_SUBCOMMAND[@]} " " ${args[@]} "
67
73
68
74
# return exit code to common::per_dir_hook
69
75
local exit_code=$?
Original file line number Diff line number Diff line change @@ -14,6 +14,14 @@ function main {
14
14
common::parse_and_export_env_vars
15
15
# JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
16
16
17
+ if common::terragrunt_version_ge_0.78; then
18
+ local -ra SUBCOMMAND=(hcl validate --inputs)
19
+ local -ra RUN_ALL_SUBCOMMAND=(run --all hcl validate --inputs)
20
+ else
21
+ local -ra SUBCOMMAND=(validate-inputs)
22
+ local -ra RUN_ALL_SUBCOMMAND=(run-all validate-inputs)
23
+ fi
24
+
17
25
# shellcheck disable=SC2153 # False positive
18
26
common::per_dir_hook " $HOOK_ID " " ${# ARGS[@]} " " ${ARGS[@]} " " ${FILES[@]} "
19
27
}
@@ -46,7 +54,7 @@ function per_dir_hook_unique_part {
46
54
local -a -r args=(" $@ " )
47
55
48
56
# pass the arguments to hook
49
- terragrunt validate-inputs " ${args[@]} "
57
+ terragrunt " ${SUBCOMMAND[@]} " " ${args[@]} "
50
58
51
59
# return exit code to common::per_dir_hook
52
60
local exit_code=$?
@@ -63,7 +71,7 @@ function run_hook_on_whole_repo {
63
71
local -a -r args=(" $@ " )
64
72
65
73
# pass the arguments to hook
66
- terragrunt run-all validate-inputs " ${args[@]} "
74
+ terragrunt " ${RUN_ALL_SUBCOMMAND[@]} " " ${args[@]} "
67
75
68
76
# return exit code to common::per_dir_hook
69
77
local exit_code=$?
You can’t perform that action at this time.
0 commit comments