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
fe5fea97
Unverified
Commit
fe5fea97
authored
8 months ago
by
Timo Furrer
Browse files
Options
Downloads
Patches
Plain Diff
Rename `TF_PLAN_CACHE` to `GITLAB_TOFU_PLAN_CACHE`
Changelog: changed
parent
999bff88
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gitlab-tofu.sh
+8
-7
8 additions, 7 deletions
src/gitlab-tofu.sh
templates/destroy.yml
+1
-1
1 addition, 1 deletion
templates/destroy.yml
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
+
8
−
7
View file @
fe5fea97
...
...
@@ -14,6 +14,7 @@
# GITLAB_TOFU_SOURCE: forces this script in source-mode. Required when source auto-detection fails.
# GITLAB_TOFU_APPLY_NO_PLAN: if set to true, the apply command does not use a plan cache file.
# 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`
#
# Respected OpenTofu Environment Variables:
# > these are variables that are
...
...
@@ -128,9 +129,9 @@ if [ -n "${TF_ROOT}" ]; then
fi
# If
TF
_PLAN_CACHE is not set then use either the plan.cache file within TF_ROOT if set, or plan.cache in CWD
if
[
-z
"
${
TF
_PLAN_CACHE
}
"
]
;
then
TF
_PLAN_CACHE
=
"
${
default_tf_plan_cache
:-${
GITLAB_TOFU_PLAN_NAME
}
.cache
}
"
# If
GITLAB_TOFU
_PLAN_CACHE is not set then use either the plan.cache file within TF_ROOT if set, or plan.cache in CWD
if
[
-z
"
${
GITLAB_TOFU
_PLAN_CACHE
}
"
]
;
then
GITLAB_TOFU
_PLAN_CACHE
=
"
${
default_tf_plan_cache
:-${
GITLAB_TOFU_PLAN_NAME
}
.cache
}
"
fi
# If TF_PLAN_JSON is not set then use either the plan.json file within TF_ROOT if set, or plan.json in CWD
...
...
@@ -234,7 +235,7 @@ if [ $sourced -eq 0 ]; then
"apply"
)
$TF_IMPLICIT_INIT
&&
terraform_init
if
[
"
$GITLAB_TOFU_APPLY_NO_PLAN
"
=
false
]
;
then
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-input
=
false
-auto-approve
"
${
TF
_PLAN_CACHE
}
"
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-input
=
false
-auto-approve
"
${
GITLAB_TOFU
_PLAN_CACHE
}
"
else
# shellcheck disable=SC2086
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-input
=
false
-auto-approve
${
var_file_args
}
...
...
@@ -260,11 +261,11 @@ if [ $sourced -eq 0 ]; then
$TF_IMPLICIT_INIT
&&
terraform_init
# shellcheck disable=SC2086
tofu
"
${
TF_CHDIR_OPT
}
"
"
${
@
}
"
-input
=
false
-out
=
"
${
TF
_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
[
"
$ret
"
-eq
0
]
||
[
"
$ret
"
-eq
2
]
;
then
if
!
tofu
"
${
TF_CHDIR_OPT
}
"
show
-json
"
${
TF
_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
TF_PLAN_JSON
}
"
;
then
if
!
tofu
"
${
TF_CHDIR_OPT
}
"
show
-json
"
${
GITLAB_TOFU
_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
TF_PLAN_JSON
}
"
;
then
exit
$?
fi
...
...
@@ -276,7 +277,7 @@ if [ $sourced -eq 0 ]; then
exit
"
$ret
"
;;
"plan-json"
)
tofu
"
${
TF_CHDIR_OPT
}
"
show
-json
"
${
TF
_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
TF_PLAN_JSON
}
"
tofu
"
${
TF_CHDIR_OPT
}
"
show
-json
"
${
GITLAB_TOFU
_PLAN_CACHE
}
"
| jq
-r
"
${
JQ_PLAN
}
"
>
"
${
TF_PLAN_JSON
}
"
;;
"validate"
)
$TF_IMPLICIT_INIT
&&
terraform_init
-backend
=
false
...
...
This diff is collapsed.
Click to expand it.
templates/destroy.yml
+
1
−
1
View file @
fe5fea97
...
...
@@ -75,7 +75,7 @@ spec:
description
:
'
Whether
a
plan
file
should
be
used.'
plan_name
:
default
:
'
destroy-plan'
description
:
'
The
name
of
the
plan
file
to
use.
Will
be
used
for
TF_PLAN_CACHE
and
TF_PLAN_JSON
.'
description
:
'
The
name
of
the
plan
file
to
use.
Will
be
used
for
the
cache
and
json
file
.'
var_file
:
default
:
'
'
type
:
string
...
...
This diff is collapsed.
Click to expand it.
tests/unit/gitlab-tofu.bats
+
4
−
4
View file @
fe5fea97
...
...
@@ -82,9 +82,9 @@ EOF
}
@test "gitlab-tofu plan" {
export
TF
_PLAN_CACHE="test-plan.cache"
export
GITLAB_TOFU
_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
if [ ! -f "$TF_ROOT/$
TF
_PLAN_CACHE" ]; then
if [ ! -f "$TF_ROOT/$
GITLAB_TOFU
_PLAN_CACHE" ]; then
echo "expected to find a plan.cache file"
exit 1
fi
...
...
@@ -97,13 +97,13 @@ EOF
}
@test "gitlab-tofu apply" {
export
TF
_PLAN_CACHE="test-plan.cache"
export
GITLAB_TOFU
_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
gitlab-tofu apply
}
@test "gitlab-tofu destroy" {
export
TF
_PLAN_CACHE="test-plan.cache"
export
GITLAB_TOFU
_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
gitlab-tofu apply
gitlab-tofu destroy
...
...
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