mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
feat: Pass custom arguments to terraform init in terraform_validate hook (#293)
This commit is contained in:
parent
7c6ad7cfb4
commit
45575c3a43
2 changed files with 17 additions and 3 deletions
10
README.md
10
README.md
|
|
@ -526,7 +526,15 @@ Example:
|
||||||
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
|
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. 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:
|
3. `terraform_validate` also supports passing custom arguments to its `terraform init`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- id: terraform_validate
|
||||||
|
args:
|
||||||
|
- --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:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo "
|
echo "
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ initialize_() {
|
||||||
|
|
||||||
parse_cmdline_() {
|
parse_cmdline_() {
|
||||||
declare argv
|
declare argv
|
||||||
argv=$(getopt -o e:a: --long envs:,args: -- "$@") || return
|
argv=$(getopt -o e:i:a: --long envs:,init-args:,args: -- "$@") || return
|
||||||
eval "set -- $argv"
|
eval "set -- $argv"
|
||||||
|
|
||||||
for argv; do
|
for argv; do
|
||||||
|
|
@ -40,6 +40,11 @@ parse_cmdline_() {
|
||||||
ARGS+=("$1")
|
ARGS+=("$1")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-i | --init-args)
|
||||||
|
shift
|
||||||
|
INIT_ARGS+=("$1")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-e | --envs)
|
-e | --envs)
|
||||||
shift
|
shift
|
||||||
ENVS+=("$1")
|
ENVS+=("$1")
|
||||||
|
|
@ -87,7 +92,7 @@ terraform_validate_() {
|
||||||
|
|
||||||
if [[ ! -d .terraform ]]; then
|
if [[ ! -d .terraform ]]; then
|
||||||
set +e
|
set +e
|
||||||
init_output=$(terraform init -backend=false 2>&1)
|
init_output=$(terraform init -backend=false "${INIT_ARGS[@]}" 2>&1)
|
||||||
init_code=$?
|
init_code=$?
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
@ -123,6 +128,7 @@ terraform_validate_() {
|
||||||
|
|
||||||
# global arrays
|
# global arrays
|
||||||
declare -a ARGS
|
declare -a ARGS
|
||||||
|
declare -a INIT_ARGS
|
||||||
declare -a ENVS
|
declare -a ENVS
|
||||||
declare -a FILES
|
declare -a FILES
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue