diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index fa5d0ff996d9c0e3798f1eb9fed0402e41825f6e..6bec4e76cda72a59c67e8fc7f7d7b3e0d4c376e3 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -328,7 +328,7 @@ we may make it the default behavior if possible. #### Lockfile Handling If you commit the Lockfile (`.terraform.lock.hcl`) to your repository -we recommend setting either the `TF_INIT_FLAGS` (handled by this component) +we recommend setting either the `GITLAB_TOFU_INIT_FLAGS` (handled by this component) or `TF_CLI_ARGS_init` (handled by OpenTofu directly) to `-lockfile=readonly` to prevent any changes to the lockfile during the pipeline job and with that ensuring that OpenTofu really uses the locked dependencies. diff --git a/README.md b/README.md index fd240c6ec324d1f1e5723be681314f63933f02ca..5e38a53022f32cb8cdf6d28336d1d38ba3e6fd35 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ we may make it the default behavior if possible. #### Lockfile Handling If you commit the Lockfile (`.terraform.lock.hcl`) to your repository -we recommend setting either the `TF_INIT_FLAGS` (handled by this component) +we recommend setting either the `GITLAB_TOFU_INIT_FLAGS` (handled by this component) or `TF_CLI_ARGS_init` (handled by OpenTofu directly) to `-lockfile=readonly` to prevent any changes to the lockfile during the pipeline job and with that ensuring that OpenTofu really uses the locked dependencies. diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index e05526e23c234884d161e64f8e0e2a862cf3ecdb..947bac39d58229b4c3025cdd3405db7b0e1d2637 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -258,9 +258,9 @@ terraform_init() { tf_init_reconfigure_flag='-reconfigure' fi - # We want to allow word splitting here for TF_INIT_FLAGS + # We want to allow word splitting here for GITLAB_TOFU_INIT_FLAGS # shellcheck disable=SC2086 - tofu "${tf_chdir_opt}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${TF_INIT_FLAGS} \ + tofu "${tf_chdir_opt}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${GITLAB_TOFU_INIT_FLAGS} \ 1>&2 || $GITLAB_TOFU_IGNORE_INIT_ERRORS } diff --git a/tests/unit/gitlab-tofu.bats b/tests/unit/gitlab-tofu.bats index f254e5cfeecf595157ac4417a54c7ef6824f96a9..44890a0e584cba526150e353a705cf72f5e374bc 100644 --- a/tests/unit/gitlab-tofu.bats +++ b/tests/unit/gitlab-tofu.bats @@ -35,12 +35,12 @@ teardown() { } @test "gitlab-tofu init with environment variable flags" { - export TF_INIT_FLAGS="-get=true -no-color" + export GITLAB_TOFU_INIT_FLAGS="-get=true -no-color" gitlab-tofu init } @test "gitlab-tofu init with args and environment variable flags" { - export TF_INIT_FLAGS="-get=true" + export GITLAB_TOFU_INIT_FLAGS="-get=true" gitlab-tofu init -no-color }