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
05a987a8
Unverified
Commit
05a987a8
authored
8 months ago
by
Timo Furrer
Browse files
Options
Downloads
Patches
Plain Diff
Support env variable to force sourcing `gitlab-tofu`
Changelog: added
parent
8d8c0d7d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab/README.md.template
+20
-0
20 additions, 0 deletions
.gitlab/README.md.template
README.md
+20
-0
20 additions, 0 deletions
README.md
src/gitlab-tofu.sh
+4
-2
4 additions, 2 deletions
src/gitlab-tofu.sh
with
44 additions
and
2 deletions
.gitlab/README.md.template
+
20
−
0
View file @
05a987a8
...
@@ -280,6 +280,26 @@ plan:
...
@@ -280,6 +280,26 @@ plan:
- apk add jq
- apk add jq
```
```
### Source `gitlab-tofu` script to run custom commands later
The `gitlab-tofu` script can be sourced instead of executed.
This allows you to setup the shell and run your own `tofu` or
`gitlab-tofu` commands.
You can use the following snipped either in your script,
directly in the shell and also in `script` keywords of your
pipeline job:
```shell
. $(which gitlab-tofu)
```
There is a slight chance when doing this in a more exotic environment
or shell that `gitlab-tofu` is not able to detect that it is sourced
and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`.
### Best Practices
### Best Practices
This section is a collection of *some* best practices.
This section is a collection of *some* best practices.
...
...
This diff is collapsed.
Click to expand it.
README.md
+
20
−
0
View file @
05a987a8
...
@@ -295,6 +295,26 @@ plan:
...
@@ -295,6 +295,26 @@ plan:
-
apk add jq
-
apk add jq
```
```
### Source `gitlab-tofu` script to run custom commands later
The
`gitlab-tofu`
script can be sourced instead of executed.
This allows you to setup the shell and run your own
`tofu`
or
`gitlab-tofu`
commands.
You can use the following snipped either in your script,
directly in the shell and also in
`script`
keywords of your
pipeline job:
```
shell
.
$(
which gitlab-tofu
)
```
There is a slight chance when doing this in a more exotic environment
or shell that
`gitlab-tofu`
is not able to detect that it is sourced
and will try to execute a
`tofu`
command.
In this case you can set the
`GITLAB_TOFU_SOURCE`
environment variable
to
`true`
before sourcing
`gitlab-tofu`
.
### Best Practices
### Best Practices
This section is a collection of
*some*
best practices.
This section is a collection of
*some*
best practices.
...
...
This diff is collapsed.
Click to expand it.
src/gitlab-tofu.sh
+
4
−
2
View file @
05a987a8
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# set some shell options
# set some shell options
set
-o
errexit
set
-o
errexit
if
[
"
${
DEBUG_OUTPUT
}
"
=
"true"
]
;
then
if
[
"
${
DEBUG_OUTPUT
}
"
=
"true"
]
;
then
set
-o
xtrace
set
-o
xtrace
fi
fi
...
@@ -24,7 +24,9 @@ fi
...
@@ -24,7 +24,9 @@ fi
# Evaluate if this script is being sourced or executed directly.
# Evaluate if this script is being sourced or executed directly.
# See https://stackoverflow.com/a/28776166
# See https://stackoverflow.com/a/28776166
sourced
=
0
sourced
=
0
if
[
-n
"
$ZSH_VERSION
"
]
;
then
if
[
"
$GITLAB_TOFU_SOURCE
"
=
'true'
]
;
then
sourced
=
1
elif
[
-n
"
$ZSH_VERSION
"
]
;
then
case
$ZSH_EVAL_CONTEXT
in
*
:file
)
sourced
=
1
;;
esac
case
$ZSH_EVAL_CONTEXT
in
*
:file
)
sourced
=
1
;;
esac
elif
[
-n
"
$KSH_VERSION
"
]
;
then
elif
[
-n
"
$KSH_VERSION
"
]
;
then
# shellcheck disable=SC2296
# shellcheck disable=SC2296
...
...
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