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
05299a7c
Unverified
Commit
05299a7c
authored
7 months ago
by
Timo Furrer
Browse files
Options
Downloads
Patches
Plain Diff
Rename internal `TF_CHDIR_OPT` variable
parent
3ce2b643
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/gitlab-tofu.sh
+16
-14
16 additions, 14 deletions
src/gitlab-tofu.sh
with
16 additions
and
14 deletions
src/gitlab-tofu.sh
+
16
−
14
View file @
05299a7c
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
# CI_JOB_TOKEN:
# CI_JOB_TOKEN:
# - used as default value for TF_HTTP_PASSWORD.
# - used as default value for TF_HTTP_PASSWORD.
# - used as value for TF_TOKEN_<host> variable.
# - used as value for TF_TOKEN_<host> variable.
# CI_PROJECT_DIR:
# - used as default value for root directory.
# set some shell options
# set some shell options
set
-o
errexit
set
-o
errexit
...
@@ -123,7 +125,7 @@ fi
...
@@ -123,7 +125,7 @@ fi
if
[
-n
"
${
TF_ROOT
}
"
]
;
then
if
[
-n
"
${
TF_ROOT
}
"
]
;
then
abs_tf_root
=
$(
cd
"
${
CI_PROJECT_DIR
}
"
;
realpath
"
${
TF_ROOT
}
"
)
abs_tf_root
=
$(
cd
"
${
CI_PROJECT_DIR
}
"
;
realpath
"
${
TF_ROOT
}
"
)
TF_CHDIR_OPT
=
"-chdir=
${
abs_tf_root
}
"
tf_chdir_opt
=
"-chdir=
${
abs_tf_root
}
"
default_tf_plan_cache
=
"
${
abs_tf_root
}
/
${
GITLAB_TOFU_PLAN_NAME
}
.cache"
default_tf_plan_cache
=
"
${
abs_tf_root
}
/
${
GITLAB_TOFU_PLAN_NAME
}
.cache"
default_tf_plan_json
=
"
${
abs_tf_root
}
/
${
GITLAB_TOFU_PLAN_NAME
}
.json"
default_tf_plan_json
=
"
${
abs_tf_root
}
/
${
GITLAB_TOFU_PLAN_NAME
}
.json"
...
@@ -216,7 +218,7 @@ terraform_init() {
...
@@ -216,7 +218,7 @@ terraform_init() {
# We want to allow word splitting here for TF_INIT_FLAGS
# We want to allow word splitting here for TF_INIT_FLAGS
# shellcheck disable=SC2086
# 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
}
${
TF_INIT_FLAGS
}
\
1>&2
||
$TF_IGNORE_INIT_ERRORS
1>&2
||
$TF_IGNORE_INIT_ERRORS
}
}
...
@@ -236,18 +238,18 @@ if [ $sourced -eq 0 ]; then
...
@@ -236,18 +238,18 @@ if [ $sourced -eq 0 ]; then
"apply"
)
"apply"
)
$TF_IMPLICIT_INIT
&&
terraform_init
$TF_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
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-input
=
false
-auto-approve
${
var_file_args
}
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-input
=
false
-auto-approve
${
var_file_args
}
fi
fi
;;
;;
"destroy"
)
"destroy"
)
$TF_IMPLICIT_INIT
&&
terraform_init
$TF_IMPLICIT_INIT
&&
terraform_init
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-auto-approve
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-auto-approve
;;
;;
"fmt"
)
"fmt"
)
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-check
-diff
-recursive
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
-check
-diff
-recursive
;;
;;
"init"
)
"init"
)
# shift argument list „one to the left“ to not call 'terraform init init'
# shift argument list „one to the left“ to not call 'terraform init init'
...
@@ -262,11 +264,11 @@ if [ $sourced -eq 0 ]; then
...
@@ -262,11 +264,11 @@ if [ $sourced -eq 0 ]; then
$TF_IMPLICIT_INIT
&&
terraform_init
$TF_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
=
$?
if
[
"
${
GITLAB_TOFU_PLAN_WITH_JSON
}
"
=
'true'
]
;
then
if
[
"
${
GITLAB_TOFU_PLAN_WITH_JSON
}
"
=
'true'
]
;
then
if
[
"
$ret
"
-eq
0
]
||
[
"
$ret
"
-eq
2
]
;
then
if
[
"
$ret
"
-eq
0
]
||
[
"
$ret
"
-eq
2
]
;
then
if
!
tofu
"
${
TF_CHDIR_OPT
}
"
show
-json
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
GITLAB_TOFU_PLAN_JSON
}
"
;
then
if
!
tofu
"
${
tf_chdir_opt
}
"
show
-json
"
${
GITLAB_TOFU_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
GITLAB_TOFU_PLAN_JSON
}
"
;
then
exit
$?
exit
$?
fi
fi
...
@@ -278,29 +280,29 @@ if [ $sourced -eq 0 ]; then
...
@@ -278,29 +280,29 @@ if [ $sourced -eq 0 ]; then
exit
"
$ret
"
exit
"
$ret
"
;;
;;
"plan-json"
)
"plan-json"
)
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
$TF_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
$TF_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
$TF_IMPLICIT_INIT
&&
terraform_init
# shellcheck disable=SC2086
# shellcheck disable=SC2086
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
${
var_file_args
}
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
${
var_file_args
}
;;
;;
--
)
--
)
shift
shift
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
;;
;;
*
)
*
)
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
tofu
"
${
tf_chdir_opt
}
"
"
${
@
}
"
;;
;;
esac
esac
else
else
...
...
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