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
73d5cd95
Commit
73d5cd95
authored
1 year ago
by
Timo Furrer
Browse files
Options
Downloads
Plain Diff
Merge branch 'auto-urlencode-state-name' into 'main'
Auto URL-encode state name See merge request components/opentofu!75
parents
87d6ee3b
43148c54
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gitlab-tofu.sh
+15
-2
15 additions, 2 deletions
src/gitlab-tofu.sh
tests/unit.gitlab-ci.yml
+53
-2
53 additions, 2 deletions
tests/unit.gitlab-ci.yml
with
68 additions
and
4 deletions
src/gitlab-tofu.sh
+
15
−
2
View file @
73d5cd95
...
...
@@ -8,6 +8,14 @@ if [ "${DEBUG_OUTPUT}" = "true" ]; then
set
-x
fi
# Feature Flags
# =============
# Below are a bunch of variables that we use as "feature flags".
if
[
-z
"
$TF_FF_AUTO_URLENCODE_STATE_NAME
"
]
;
then
TF_FF_AUTO_URLENCODE_STATE_NAME
=
true
fi
# Helpers
# Evaluate if this script is being sourced or executed directly.
...
...
@@ -45,8 +53,13 @@ if [ -z "${TF_PASSWORD}" ]; then
fi
# If TF_ADDRESS is unset but TF_STATE_NAME is provided, then default to GitLab backend in current project
if
[
-n
"
${
TF_STATE_NAME
}
"
]
;
then
TF_ADDRESS
=
"
${
TF_ADDRESS
:-${
CI_API_V4_URL
}
/projects/
${
CI_PROJECT_ID
}
/terraform/state/
${
TF_STATE_NAME
}}
"
if
[
-n
"
${
TF_STATE_NAME
}
"
]
&&
[
-z
"
${
TF_ADDRESS
}
"
]
;
then
# auto url-encode TF_STATE_NAME when FF is enabled
if
$TF_FF_AUTO_URLENCODE_STATE_NAME
;
then
TF_STATE_NAME
=
"
$(
jq
-rn
--arg
x
"
${
TF_STATE_NAME
}
"
'$x|@uri'
)
"
fi
TF_ADDRESS
=
"
${
CI_API_V4_URL
}
/projects/
${
CI_PROJECT_ID
}
/terraform/state/
${
TF_STATE_NAME
}
"
fi
# If TF_ROOT is set then use the -chdir option
...
...
This diff is collapsed.
Click to expand it.
tests/unit.gitlab-ci.yml
+
53
−
2
View file @
73d5cd95
...
...
@@ -160,7 +160,7 @@ gitlab-tofu-init-with-prepared-registry-token:
-
|
cat <<'EOF' > test.sh
set -x
# NOTE: as part of the tst fixture, we need to overwrite the CI_SERVER_HOST,
# NOTE: as part of the t
e
st fixture, we need to overwrite the CI_SERVER_HOST,
# so that this test also properly works on GitLab self-managed.
export CI_SERVER_HOST=gitlab.example.com
export TF_TOKEN_gitlab_example_com=mysecrettoken
...
...
@@ -189,7 +189,7 @@ gitlab-tofu-init-without-prepared-registry-token:
-
|
cat <<'EOF' > test.sh
set -x
# NOTE: as part of the tst fixture, we need to overwrite the CI_SERVER_HOST,
# NOTE: as part of the t
e
st fixture, we need to overwrite the CI_SERVER_HOST,
# so that this test also properly works on GitLab self-managed.
export CI_SERVER_HOST=gitlab.example.com
. $(which gitlab-tofu)
...
...
@@ -340,3 +340,54 @@ gitlab-tofu-no-wrapper:
-
cat /tmp/output.txt
-
test $FAILED =
true
-
'
grep
"Error:
Backend
initialization
required,
please
run
\"tofu
init\""
/tmp/output.txt'
gitlab-tofu-state-name-auto-urlencode
:
extends
:
-
.gitlab-tofu-test
stage
:
test
variables
:
OPENTOFU_VERSION
:
$LATEST_OPENTOFU_VERSION
script
:
-
apk add --update $PKG
-
|
cat <<'EOF' > test.sh
set -x
export TF_STATE_NAME=production/europe
. $(which gitlab-tofu)
test "$TF_STATE_NAME" = "production%2Feurope"
EOF
-
$SHELL test.sh
parallel
:
matrix
:
-
SHELL
:
"
bash"
PKG
:
"
bash"
-
SHELL
:
"
zsh"
PKG
:
"
zsh"
-
SHELL
:
"
ksh"
PKG
:
"
loksh"
gitlab-tofu-state-name-auto-urlencode-ff-disabled
:
extends
:
-
.gitlab-tofu-test
stage
:
test
variables
:
OPENTOFU_VERSION
:
$LATEST_OPENTOFU_VERSION
script
:
-
apk add --update $PKG
-
|
cat <<'EOF' > test.sh
set -x
export TF_FF_AUTO_URLENCODE_STATE_NAME=false
export TF_STATE_NAME=production/europe
. $(which gitlab-tofu)
test "$TF_STATE_NAME" = "production/europe"
EOF
-
$SHELL test.sh
parallel
:
matrix
:
-
SHELL
:
"
bash"
PKG
:
"
bash"
-
SHELL
:
"
zsh"
PKG
:
"
zsh"
-
SHELL
:
"
ksh"
PKG
:
"
loksh"
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