mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
fix: Add --tf-init-args, deprecate --init-args (#407)
This commit is contained in:
parent
32b232f039
commit
c4f8251d30
3 changed files with 15 additions and 13 deletions
|
|
@ -520,7 +520,7 @@ Example:
|
||||||
```yaml
|
```yaml
|
||||||
- id: terraform_providers_lock
|
- id: terraform_providers_lock
|
||||||
args:
|
args:
|
||||||
- --init-args=-upgrade
|
- --tf-init-args=-upgrade
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -629,7 +629,7 @@ Example:
|
||||||
```yaml
|
```yaml
|
||||||
- id: terraform_validate
|
- id: terraform_validate
|
||||||
args:
|
args:
|
||||||
- --init-args=-lockfile=readonly
|
- --tf-init-args=-lockfile=readonly
|
||||||
```
|
```
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ function common::initialize {
|
||||||
# Globals (init and populate):
|
# Globals (init and populate):
|
||||||
# ARGS (array) arguments that configure wrapped tool behavior
|
# ARGS (array) arguments that configure wrapped tool behavior
|
||||||
# HOOK_CONFIG (array) arguments that configure hook behavior
|
# HOOK_CONFIG (array) arguments that configure hook behavior
|
||||||
# INIT_ARGS (array) arguments for `terraform init` command
|
# TF_INIT_ARGS (array) arguments for `terraform init` command
|
||||||
# FILES (array) filenames to check
|
# FILES (array) filenames to check
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# $@ (array) all specified in `hooks.[].args` in
|
# $@ (array) all specified in `hooks.[].args` in
|
||||||
|
|
@ -36,10 +36,10 @@ function common::parse_cmdline {
|
||||||
# Populated via `common::parse_cmdline` and can be used inside hooks' functions
|
# Populated via `common::parse_cmdline` and can be used inside hooks' functions
|
||||||
ARGS=() HOOK_CONFIG=() FILES=()
|
ARGS=() HOOK_CONFIG=() FILES=()
|
||||||
# Used inside `common::terraform_init` function
|
# Used inside `common::terraform_init` function
|
||||||
INIT_ARGS=()
|
TF_INIT_ARGS=()
|
||||||
|
|
||||||
local argv
|
local argv
|
||||||
argv=$(getopt -o a:,h: --long args:,hook-config: -- "$@") || return
|
argv=$(getopt -o a:,h:,i: --long args:,hook-config:,init-args:,tf-init-args: -- "$@") || return
|
||||||
eval "set -- $argv"
|
eval "set -- $argv"
|
||||||
|
|
||||||
for argv; do
|
for argv; do
|
||||||
|
|
@ -54,9 +54,10 @@ function common::parse_cmdline {
|
||||||
HOOK_CONFIG+=("$1;")
|
HOOK_CONFIG+=("$1;")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-i | --init-args)
|
# TODO: Planned breaking change: remove `--init-args` as not self-descriptive
|
||||||
|
-i | --init-args | --tf-init-args)
|
||||||
shift
|
shift
|
||||||
INIT_ARGS+=("$1")
|
TF_INIT_ARGS+=("$1")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
|
@ -246,7 +247,7 @@ function common::colorify {
|
||||||
# dir_path (string) PATH to dir relative to git repo root.
|
# dir_path (string) PATH to dir relative to git repo root.
|
||||||
# Can be used in error logging
|
# Can be used in error logging
|
||||||
# Globals (init and populate):
|
# Globals (init and populate):
|
||||||
# INIT_ARGS (array) arguments for `terraform init` command
|
# TF_INIT_ARGS (array) arguments for `terraform init` command
|
||||||
# Outputs:
|
# Outputs:
|
||||||
# If failed - print out terraform init output
|
# If failed - print out terraform init output
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
@ -258,7 +259,7 @@ function common::terraform_init {
|
||||||
local init_output
|
local init_output
|
||||||
|
|
||||||
if [ ! -d .terraform ]; then
|
if [ ! -d .terraform ]; then
|
||||||
init_output=$(terraform init -backend=false "${INIT_ARGS[@]}" 2>&1)
|
init_output=$(terraform init -backend=false "${TF_INIT_ARGS[@]}" 2>&1)
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
if [ $exit_code -ne 0 ]; then
|
if [ $exit_code -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ function main {
|
||||||
# Globals (init and populate):
|
# Globals (init and populate):
|
||||||
# ARGS (array) arguments that configure wrapped tool behavior
|
# ARGS (array) arguments that configure wrapped tool behavior
|
||||||
# HOOK_CONFIG (array) arguments that configure hook behavior
|
# HOOK_CONFIG (array) arguments that configure hook behavior
|
||||||
# INIT_ARGS (array) arguments to `terraform init` command
|
# TF_INIT_ARGS (array) arguments to `terraform init` command
|
||||||
# ENVS (array) environment variables that will be used with
|
# ENVS (array) environment variables that will be used with
|
||||||
# `terraform` commands
|
# `terraform` commands
|
||||||
# FILES (array) filenames to check
|
# FILES (array) filenames to check
|
||||||
|
|
@ -44,7 +44,7 @@ function main {
|
||||||
#######################################################################
|
#######################################################################
|
||||||
function parse_cmdline_ {
|
function parse_cmdline_ {
|
||||||
declare argv
|
declare argv
|
||||||
argv=$(getopt -o e:i:a: --long envs:,init-args:,args: -- "$@") || return
|
argv=$(getopt -o e:i:a:h: --long envs:,tf-init-args:,init-args:,args: -- "$@") || return
|
||||||
eval "set -- $argv"
|
eval "set -- $argv"
|
||||||
|
|
||||||
for argv; do
|
for argv; do
|
||||||
|
|
@ -59,9 +59,10 @@ function parse_cmdline_ {
|
||||||
HOOK_CONFIG+=("$1;")
|
HOOK_CONFIG+=("$1;")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-i | --init-args)
|
# TODO: Planned breaking change: remove `--init-args` as not self-descriptive
|
||||||
|
-i | --init-args | --tf-init-args)
|
||||||
shift
|
shift
|
||||||
INIT_ARGS+=("$1")
|
TF_INIT_ARGS+=("$1")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-e | --envs)
|
-e | --envs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue