Repository navigation
feat: Support one CI variable key in many environment scopes - #13
Merged
Merged
Conversation
A key that occurs once in its resource keeps the address "<owner>-<KEY>". A key that occurs more than once gets the suffix ":<environment_scope>". Current addresses do not change. Apply the rule to gitlab_project_variable and gitlab_group_variable. Validate that each key and environment_scope pair is unique per owner. Add unit tests with a mock provider, an example, and docs.
wiseelf
requested review from
babychm,
chas0amx,
kushlychok,
perun-ai and
sirantd
October 22, 2026 23:14
github-actions Bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
## [2.2.0](v2.1.0...v2.2.0) (2026-10-22) ### Features * Support one CI variable key in many environment scopes ([#13](#13)) ([87220b6](87220b6))
|
This PR is included in version 2.2.0 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The module keys each CI variable by owner and key only:
<namespace>-<project>-<KEY>for projects and<group path>-<KEY>for groups.If a project or group has one key in two
environment_scopevalues, the plan fails withDuplicate object key.Thus a consumer cannot manage per-environment variables, for example
UI_BUCKETinui-uatand inui-production.What
Key rule (
main.tf): a newci_variableslocal builds thefor_eachmaps forgitlab_project_variableandgitlab_group_variable(thisandthis_sensitive).<namespace>-<project>-<KEY><group path>-<KEY><namespace>-<project>-<KEY>:<environment_scope><group path>-<KEY>:<environment_scope>A key that occurs once keeps its current address, so current state does not move. No
movedblocks are necessary. The module counts keys per resource (masked or unmasked), not per owner. Today a config can have a key masked in one scope and unmasked in another scope, and that config plans. A count per owner gives both variables new addresses, and Terraform destroys and creates them again.The rule "add the scope when the scope is not
*" was rejected. With that rule, a unique variable with a scope other than*gets a new address.Validation (
variables.tf):gitlab_groupsandgitlab_projectsfail at plan if one owner has two variables with the same key andenvironment_scope. This also includes a masked/unmasked pair. Before this change, such a pair passed the plan and failed at apply.Tests (
tests/ci_variables.tftest.hcl): 5terraform testruns with a mock provider. They check the addresses of unique keys, the scope suffix for repeated keys, the failure on duplicate pairs, and the example config.Example and docs:
project-betainexamples/terraform/projects/alpha_projects.yamlhasDEPLOY_ROLE_ARNinuatandproduction.Readme.mddescribes the key rule and the address change.Caution for consumers: if you add a second scope to a key that occurs once, the address of the first variable changes. The same occurs when you remove scopes until a key occurs once. Add a
movedblock in the root module before you apply.Readme.mdshows an example.Checks
terraform validate: Success.terraform test: 5 passed, 0 failed.terraform testwith the oldmain.tfandvariables.tf: the first run fails withDuplicate object key, so the tests detect the defect.pre-commit run -a(all hooks, includingterraform_tflint): Passed.Notes for reviewers
for_eachkey, the plan now fails. Before,merge()silently dropped one variable. Example: namespacea-bwith projectc, and namespaceawith projectb-c.maskedis nottrueorfalse(for examplenull) now goes tothis. Before, the module dropped it.