Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenTofu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
components
OpenTofu
Commits
d731c2b9
Unverified
Commit
d731c2b9
authored
7 months ago
by
Timo Furrer
Browse files
Options
Downloads
Patches
Plain Diff
Rename `TF_IMPLICIT_INIT` to `GITLAB_TOFU_IMPLICIT_INIT`
Changelog: changed
parent
05299a7c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gitlab-tofu.sh
+9
-8
9 additions, 8 deletions
src/gitlab-tofu.sh
tests/unit/gitlab-tofu.bats
+4
-4
4 additions, 4 deletions
tests/unit/gitlab-tofu.bats
with
13 additions
and
12 deletions
src/gitlab-tofu.sh
+
9
−
8
View file @
d731c2b9
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
# GITLAB_TOFU_PLAN_NAME: the name of the plan cache and json files. Defaults to `plan`.
# GITLAB_TOFU_PLAN_NAME: the name of the plan cache and json files. Defaults to `plan`.
# GITLAB_TOFU_PLAN_CACHE: if set is the full path of the plan cache file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.cache`
# GITLAB_TOFU_PLAN_CACHE: if set is the full path of the plan cache file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.cache`
# GITLAB_TOFU_PLAN_JSON: if set is the full path of the plan json file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.json`
# GITLAB_TOFU_PLAN_JSON: if set is the full path of the plan json file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.json`
# GITLAB_TOFU_IMPLICIT_INIT: if set to true will perform an implicit tofu init before any command that require it. Defaults to `true`.
#
#
# Respected OpenTofu Environment Variables:
# Respected OpenTofu Environment Variables:
# > these are variables that are
# > these are variables that are
...
@@ -201,10 +202,10 @@ terraform_authenticate_private_registry() {
...
@@ -201,10 +202,10 @@ terraform_authenticate_private_registry() {
fi
fi
}
}
# If
TF
_IMPLICIT_INIT is not set, we set it to `true`.
# If
GITLAB_TOFU
_IMPLICIT_INIT is not set, we set it to `true`.
# If set to `true` it will call `terraform init` prior
# If set to `true` it will call `terraform init` prior
# to calling the wrapper `terraform` commands.
# to calling the wrapper `terraform` commands.
TF
_IMPLICIT_INIT
=
${
TF
_IMPLICIT_INIT
:-
true
}
GITLAB_TOFU
_IMPLICIT_INIT
=
${
GITLAB_TOFU
_IMPLICIT_INIT
:-
true
}
# Allows users to continue the actual command in case init failed
# Allows users to continue the actual command in case init failed
TF_IGNORE_INIT_ERRORS
=
${
TF_IGNORE_INIT_ERRORS
:-
false
}
TF_IGNORE_INIT_ERRORS
=
${
TF_IGNORE_INIT_ERRORS
:-
false
}
...
@@ -236,7 +237,7 @@ if [ $sourced -eq 0 ]; then
...
@@ -236,7 +237,7 @@ if [ $sourced -eq 0 ]; then
case
"
${
1
}
"
in
case
"
${
1
}
"
in
"apply"
)
"apply"
)
$
TF
_IMPLICIT_INIT
&&
terraform_init
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
if
[
"
$GITLAB_TOFU_APPLY_NO_PLAN
"
=
false
]
;
then
if
[
"
$GITLAB_TOFU_APPLY_NO_PLAN
"
=
false
]
;
then
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-input
=
false
-auto-approve
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-input
=
false
-auto-approve
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
else
else
...
@@ -245,7 +246,7 @@ if [ $sourced -eq 0 ]; then
...
@@ -245,7 +246,7 @@ if [ $sourced -eq 0 ]; then
fi
fi
;;
;;
"destroy"
)
"destroy"
)
$
TF
_IMPLICIT_INIT
&&
terraform_init
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-auto-approve
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-auto-approve
;;
;;
"fmt"
)
"fmt"
)
...
@@ -262,7 +263,7 @@ if [ $sourced -eq 0 ]; then
...
@@ -262,7 +263,7 @@ if [ $sourced -eq 0 ]; then
plan_args
=
'-detailed-exitcode'
plan_args
=
'-detailed-exitcode'
fi
fi
$
TF
_IMPLICIT_INIT
&&
terraform_init
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-input
=
false
-out
=
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
${
var_file_args
}
${
plan_args
}
&&
ret
=
$?
||
ret
=
$?
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-input
=
false
-out
=
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
${
var_file_args
}
${
plan_args
}
&&
ret
=
$?
||
ret
=
$?
...
@@ -283,17 +284,17 @@ if [ $sourced -eq 0 ]; then
...
@@ -283,17 +284,17 @@ if [ $sourced -eq 0 ]; then
tofu
"
${
tf_chdir_opt
}
"
show
-json
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
GITLAB_TOFU_PLAN_JSON
}
"
tofu
"
${
tf_chdir_opt
}
"
show
-json
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
GITLAB_TOFU_PLAN_JSON
}
"
;;
;;
"validate"
)
"validate"
)
$
TF
_IMPLICIT_INIT
&&
terraform_init
-backend
=
false
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
-backend
=
false
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
;;
;;
"test"
)
"test"
)
$
TF
_IMPLICIT_INIT
&&
terraform_init
-backend
=
false
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
-backend
=
false
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
;;
;;
"graph"
)
"graph"
)
$
TF
_IMPLICIT_INIT
&&
terraform_init
$
GITLAB_TOFU
_IMPLICIT_INIT
&&
terraform_init
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
;;
;;
...
...
This diff is collapsed.
Click to expand it.
tests/unit/gitlab-tofu.bats
+
4
−
4
View file @
d731c2b9
...
@@ -110,28 +110,28 @@ EOF
...
@@ -110,28 +110,28 @@ EOF
}
}
@test "gitlab-tofu validate without implicit init" {
@test "gitlab-tofu validate without implicit init" {
export
TF
_IMPLICIT_INIT=false
export
GITLAB_TOFU
_IMPLICIT_INIT=false
run ! gitlab-tofu validate -no-color
run ! gitlab-tofu validate -no-color
assert_output --partial 'This module is not yet installed'
assert_output --partial 'This module is not yet installed'
}
}
@test "gitlab-tofu plan without implicit init" {
@test "gitlab-tofu plan without implicit init" {
export
TF
_IMPLICIT_INIT=false
export
GITLAB_TOFU
_IMPLICIT_INIT=false
run ! gitlab-tofu plan -no-color
run ! gitlab-tofu plan -no-color
assert_output --partial 'Error: Backend initialization required'
assert_output --partial 'Error: Backend initialization required'
}
}
@test "gitlab-tofu apply without implicit init" {
@test "gitlab-tofu apply without implicit init" {
export
TF
_IMPLICIT_INIT=false
export
GITLAB_TOFU
_IMPLICIT_INIT=false
run ! gitlab-tofu apply -no-color
run ! gitlab-tofu apply -no-color
assert_output --partial 'Error: Failed to load '
assert_output --partial 'Error: Failed to load '
}
}
@test "gitlab-tofu destroy without implicit init" {
@test "gitlab-tofu destroy without implicit init" {
export
TF
_IMPLICIT_INIT=false
export
GITLAB_TOFU
_IMPLICIT_INIT=false
run ! gitlab-tofu destroy -no-color
run ! gitlab-tofu destroy -no-color
assert_output --partial 'Error: Backend initialization required'
assert_output --partial 'Error: Backend initialization required'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment