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
fe2f4e9b
Unverified
Commit
fe2f4e9b
authored
10 months ago
by
Timo Furrer
Browse files
Options
Downloads
Patches
Plain Diff
Document auto-forwarding of CI/CD variables
parent
d6a183be
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
.gitlab/README.md.template
+28
-0
28 additions, 0 deletions
.gitlab/README.md.template
README.md
+28
-0
28 additions, 0 deletions
README.md
src/gitlab-tofu.sh
+12
-1
12 additions, 1 deletion
src/gitlab-tofu.sh
with
68 additions
and
1 deletion
.gitlab/README.md.template
+
28
−
0
View file @
fe2f4e9b
...
@@ -220,6 +220,34 @@ beautifully renders the inputs for each templates - check it out!
...
@@ -220,6 +220,34 @@ beautifully renders the inputs for each templates - check it out!
Have a look at the [`src/gitlab-tofu.sh`](src/gitlab-tofu.sh) script and how the `TF_`-prefixed
Have a look at the [`src/gitlab-tofu.sh`](src/gitlab-tofu.sh) script and how the `TF_`-prefixed
variables are being used. You may set them according to your needs.
variables are being used. You may set them according to your needs.
### Auto-forwarded predefined CI variables
The `gitlab-tofu` script auto-forwards some "popular"
[predefined CI/CD variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
as OpenTofu variables.
The forwarded variables are:
- `CI_JOB_ID`
- `CI_COMMIT_SHA`
- `CI_JOB_STAGE`
- `CI_PROJECT_ID`
- `CI_PROJECT_NAME`
- `CI_PROJECT_NAMESPACE`
- `CI_PROJECT_PATH`
- `CI_PROJECT_URL`
To use them in your OpenTofu configuration you can define a string variable with the same name
but in *lower snake_case*. For example the `CI_PROJECT_NAME` CI/CD variable can be accessed in
the OpenTofu configuration like this:
```hcl
variable "ci_project_name" {
type = string
description = "The name of the directory for the project."
}
```
### Install additional tools
### Install additional tools
The `gitlab-opentofu` container image deliberately comes with minimal tooling
The `gitlab-opentofu` container image deliberately comes with minimal tooling
...
...
This diff is collapsed.
Click to expand it.
README.md
+
28
−
0
View file @
fe2f4e9b
...
@@ -237,6 +237,34 @@ The following OpenTofu versions are available with this component via the `opent
...
@@ -237,6 +237,34 @@ The following OpenTofu versions are available with this component via the `opent
Have a look at the
[
`src/gitlab-tofu.sh`
](
src/gitlab-tofu.sh
)
script and how the
`TF_`
-prefixed
Have a look at the
[
`src/gitlab-tofu.sh`
](
src/gitlab-tofu.sh
)
script and how the
`TF_`
-prefixed
variables are being used. You may set them according to your needs.
variables are being used. You may set them according to your needs.
### Auto-forwarded predefined CI variables
The
`gitlab-tofu`
script auto-forwards some "popular"
[
predefined CI/CD variables
](
https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
)
as OpenTofu variables.
The forwarded variables are:
-
`CI_JOB_ID`
-
`CI_COMMIT_SHA`
-
`CI_JOB_STAGE`
-
`CI_PROJECT_ID`
-
`CI_PROJECT_NAME`
-
`CI_PROJECT_NAMESPACE`
-
`CI_PROJECT_PATH`
-
`CI_PROJECT_URL`
To use them in your OpenTofu configuration you can define a string variable with the same name
but in
*lower snake_case*
. For example the
`CI_PROJECT_NAME`
CI/CD variable can be accessed in
the OpenTofu configuration like this:
```
hcl
variable
"ci_project_name"
{
type
=
string
description
=
"The name of the directory for the project."
}
```
### Install additional tools
### Install additional tools
The
`gitlab-opentofu`
container image deliberately comes with minimal tooling
The
`gitlab-opentofu`
container image deliberately comes with minimal tooling
...
...
This diff is collapsed.
Click to expand it.
src/gitlab-tofu.sh
+
12
−
1
View file @
fe2f4e9b
...
@@ -106,7 +106,8 @@ export TF_HTTP_PASSWORD="${TF_HTTP_PASSWORD:-${TF_PASSWORD}}"
...
@@ -106,7 +106,8 @@ export TF_HTTP_PASSWORD="${TF_HTTP_PASSWORD:-${TF_PASSWORD}}"
export
TF_HTTP_RETRY_WAIT_MIN
=
"
${
TF_HTTP_RETRY_WAIT_MIN
:-
5
}
"
export
TF_HTTP_RETRY_WAIT_MIN
=
"
${
TF_HTTP_RETRY_WAIT_MIN
:-
5
}
"
# Expose Gitlab specific variables to terraform since no -tf-var is available
# Expose Gitlab specific variables to terraform since no -tf-var is available
# Usable in the .tf file as variable "CI_JOB_ID" { type = string } etc
# The following variables are deprecated because they do not conform to
# HCL naming best practices. Use the lower snake_case variants below instead.
export
TF_VAR_CI_JOB_ID
=
"
${
TF_VAR_CI_JOB_ID
:-${
CI_JOB_ID
}}
"
export
TF_VAR_CI_JOB_ID
=
"
${
TF_VAR_CI_JOB_ID
:-${
CI_JOB_ID
}}
"
export
TF_VAR_CI_COMMIT_SHA
=
"
${
TF_VAR_CI_COMMIT_SHA
:-${
CI_COMMIT_SHA
}}
"
export
TF_VAR_CI_COMMIT_SHA
=
"
${
TF_VAR_CI_COMMIT_SHA
:-${
CI_COMMIT_SHA
}}
"
export
TF_VAR_CI_JOB_STAGE
=
"
${
TF_VAR_CI_JOB_STAGE
:-${
CI_JOB_STAGE
}}
"
export
TF_VAR_CI_JOB_STAGE
=
"
${
TF_VAR_CI_JOB_STAGE
:-${
CI_JOB_STAGE
}}
"
...
@@ -116,6 +117,16 @@ export TF_VAR_CI_PROJECT_NAMESPACE="${TF_VAR_CI_PROJECT_NAMESPACE:-${CI_PROJECT_
...
@@ -116,6 +117,16 @@ export TF_VAR_CI_PROJECT_NAMESPACE="${TF_VAR_CI_PROJECT_NAMESPACE:-${CI_PROJECT_
export
TF_VAR_CI_PROJECT_PATH
=
"
${
TF_VAR_CI_PROJECT_PATH
:-${
CI_PROJECT_PATH
}}
"
export
TF_VAR_CI_PROJECT_PATH
=
"
${
TF_VAR_CI_PROJECT_PATH
:-${
CI_PROJECT_PATH
}}
"
export
TF_VAR_CI_PROJECT_URL
=
"
${
TF_VAR_CI_PROJECT_URL
:-${
CI_PROJECT_URL
}}
"
export
TF_VAR_CI_PROJECT_URL
=
"
${
TF_VAR_CI_PROJECT_URL
:-${
CI_PROJECT_URL
}}
"
export
TF_VAR_ci_job_id
=
"
${
TF_VAR_ci_job_id
:-${
CI_JOB_ID
}}
"
export
TF_VAR_ci_commit_sha
=
"
${
TF_VAR_ci_commit_sha
:-${
CI_COMMIT_SHA
}}
"
export
TF_VAR_ci_job_stage
=
"
${
TF_VAR_ci_job_stage
:-${
CI_JOB_STAGE
}}
"
export
TF_VAR_ci_project_id
=
"
${
TF_VAR_ci_project_id
:-${
CI_PROJECT_ID
}}
"
export
TF_VAR_ci_project_name
=
"
${
TF_VAR_ci_project_name
:-${
CI_PROJECT_NAME
}}
"
export
TF_VAR_ci_project_namespace
=
"
${
TF_VAR_ci_project_namespace
:-${
CI_PROJECT_NAMESPACE
}}
"
export
TF_VAR_ci_project_path
=
"
${
TF_VAR_ci_project_path
:-${
CI_PROJECT_PATH
}}
"
export
TF_VAR_ci_project_url
=
"
${
TF_VAR_ci_project_url
:-${
CI_PROJECT_URL
}}
"
# Use terraform automation mode (will remove some verbose unneeded messages)
# Use terraform automation mode (will remove some verbose unneeded messages)
export
TF_IN_AUTOMATION
=
true
export
TF_IN_AUTOMATION
=
true
...
...
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