Skip to content

fix: Create protected environments after project group shares - #17

Merged
sirantd merged 1 commit into
mainfrom
fix/protected-env-after-share
Oct 29, 2026
Merged

sirantd merged 1 commit into
mainfrom
fix/protected-env-after-share

Conversation

@sirantd

@sirantd sirantd commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Why

GitLab accepts a group in a protected environment's deploy access levels (and approval rules) only when that group is shared on the project itself. Access inherited through a parent group doesn't count. Otherwise GitLab drops the group without an error. gitlab_project_protected_environment had no dependency on gitlab_project_share_group, so when an apply shared a group and protected an environment for it at once, Terraform ran both in parallel.

That's what happened in a real apply: the share for the deploy group was created after the environment POST had been sent. GitLab discarded the not-yet-shared group, which left the list empty, and rejected the request:

23:56:56.955  gitlab_project_protected_environment.this["infra/mc-infrastructure-aws-dev"]: Creating...
23:56:57.843  gitlab_project_share_group.this["infra/mc-infrastructure-roles/mc-sre-dev"]: Creation complete
POST /projects/272/protected_environments:
422 {message: [Deploy access levels is too short (minimum is 1 character)]}

The plan succeeded, and re-planning and applying again after the share existed created the environment. So this is purely an ordering problem.

What

  • gitlab_project_protected_environment.this gets depends_on = [gitlab_project_share_group.this], so project shares are created before protected environments, and the environment is destroyed before the share.

terraform validate and terraform test (12 passed) are green. A mock provider can't reproduce the API-side ordering, so no test was added.

🤖 Generated with Claude Code

GitLab accepts a group in an environment's deploy access levels or
approval rules only when the group is shared on the project itself, and
drops it otherwise. When an apply shared a group and protected an
environment for it at once, the environment POST could run first and
fail with "Deploy access levels is too short (minimum is 1 character)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sirantd sirantd self-assigned this Oct 29, 2026
@wiseelf
wiseelf self-requested a review October 29, 2026 00:30

@wiseelf wiseelf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sirantd
sirantd merged commit cc833ee into main Oct 29, 2026
2 checks passed
@sirantd
sirantd deleted the fix/protected-env-after-share branch October 29, 2026 00:30
@github-actions

Copy link
Copy Markdown

This PR is included in version 2.3.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants