Skip to content

Commit c4f8251

Browse files
MaxymVlasovantonbabenko
authored andcommitted
fix: Add --tf-init-args, deprecate --init-args (antonbabenko#407)
1 parent 32b232f commit c4f8251

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ Example:
520520
```yaml
521521
- id: terraform_providers_lock
522522
args:
523-
- --init-args=-upgrade
523+
- --tf-init-args=-upgrade
524524
```
525525

526526

@@ -629,7 +629,7 @@ Example:
629629
```yaml
630630
- id: terraform_validate
631631
args:
632-
- --init-args=-lockfile=readonly
632+
- --tf-init-args=-lockfile=readonly
633633
```
634634

635635
4. It may happen that Terraform working directory (`.terraform`) already exists but not in the best condition (eg, not initialized modules, wrong version of Terraform, etc.). To solve this problem, you can find and delete all `.terraform` directories in your repository:

hooks/_common.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function common::initialize {
2525
# Globals (init and populate):
2626
# ARGS (array) arguments that configure wrapped tool behavior
2727
# HOOK_CONFIG (array) arguments that configure hook behavior
28-
# INIT_ARGS (array) arguments for `terraform init` command
28+
# TF_INIT_ARGS (array) arguments for `terraform init` command
2929
# FILES (array) filenames to check
3030
# Arguments:
3131
# $@ (array) all specified in `hooks.[].args` in
@@ -36,10 +36,10 @@ function common::parse_cmdline {
3636
# Populated via `common::parse_cmdline` and can be used inside hooks' functions
3737
ARGS=() HOOK_CONFIG=() FILES=()
3838
# Used inside `common::terraform_init` function
39-
INIT_ARGS=()
39+
TF_INIT_ARGS=()
4040

4141
local argv
42-
argv=$(getopt -o a:,h: --long args:,hook-config: -- "$@") || return
42+
argv=$(getopt -o a:,h:,i: --long args:,hook-config:,init-args:,tf-init-args: -- "$@") || return
4343
eval "set -- $argv"
4444

4545
for argv; do
@@ -54,9 +54,10 @@ function common::parse_cmdline {
5454
HOOK_CONFIG+=("$1;")
5555
shift
5656
;;
57-
-i | --init-args)
57+
# TODO: Planned breaking change: remove `--init-args` as not self-descriptive
58+
-i | --init-args | --tf-init-args)
5859
shift
59-
INIT_ARGS+=("$1")
60+
TF_INIT_ARGS+=("$1")
6061
shift
6162
;;
6263
--)
@@ -246,7 +247,7 @@ function common::colorify {
246247
# dir_path (string) PATH to dir relative to git repo root.
247248
# Can be used in error logging
248249
# Globals (init and populate):
249-
# INIT_ARGS (array) arguments for `terraform init` command
250+
# TF_INIT_ARGS (array) arguments for `terraform init` command
250251
# Outputs:
251252
# If failed - print out terraform init output
252253
#######################################################################
@@ -258,7 +259,7 @@ function common::terraform_init {
258259
local init_output
259260

260261
if [ ! -d .terraform ]; then
261-
init_output=$(terraform init -backend=false "${INIT_ARGS[@]}" 2>&1)
262+
init_output=$(terraform init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
262263
exit_code=$?
263264

264265
if [ $exit_code -ne 0 ]; then

hooks/terraform_validate.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function main {
3434
# Globals (init and populate):
3535
# ARGS (array) arguments that configure wrapped tool behavior
3636
# HOOK_CONFIG (array) arguments that configure hook behavior
37-
# INIT_ARGS (array) arguments to `terraform init` command
37+
# TF_INIT_ARGS (array) arguments to `terraform init` command
3838
# ENVS (array) environment variables that will be used with
3939
# `terraform` commands
4040
# FILES (array) filenames to check
@@ -44,7 +44,7 @@ function main {
4444
#######################################################################
4545
function parse_cmdline_ {
4646
declare argv
47-
argv=$(getopt -o e:i:a: --long envs:,init-args:,args: -- "$@") || return
47+
argv=$(getopt -o e:i:a:h: --long envs:,tf-init-args:,init-args:,args: -- "$@") || return
4848
eval "set -- $argv"
4949

5050
for argv; do
@@ -59,9 +59,10 @@ function parse_cmdline_ {
5959
HOOK_CONFIG+=("$1;")
6060
shift
6161
;;
62-
-i | --init-args)
62+
# TODO: Planned breaking change: remove `--init-args` as not self-descriptive
63+
-i | --init-args | --tf-init-args)
6364
shift
64-
INIT_ARGS+=("$1")
65+
TF_INIT_ARGS+=("$1")
6566
shift
6667
;;
6768
-e | --envs)

0 commit comments

Comments
 (0)