Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/gitlab_project: fix waiting for default branch protection during creation #908

Merged
merged 1 commit into from
Mar 2, 2022

Conversation

timofurrer
Copy link
Member

This patch fixes waiting for the protection on the default branch in a
scenario where the project is in a group namespace which has the default
branch protection disabled.

NOTE: I've made some assumption that this can only happen for the
projects in group namespaces (e.g. project in a user namespace can't
turn the default branch protection off) and that this information about
the disabled default branch protection can always be read from the group
the project is directly assigned to.

Closes #906
Caused by #862

/cc @PatrickRice-KSC @armsnyder as you can read above I've made some assumptions. Can any of you confirm these?

@timofurrer timofurrer added this to the v3.11.0 milestone Mar 1, 2022
@timofurrer timofurrer requested a review from armsnyder March 1, 2022 08:51
@timofurrer timofurrer self-assigned this Mar 1, 2022
@github-actions github-actions bot added provider resource Adds or modifies a resource tests size/M labels Mar 1, 2022
@timofurrer timofurrer modified the milestones: v3.11.0, v3.11.1 Mar 1, 2022
…ring creation

This patch fixes waiting for the protection on the default branch in a
scenario where the project is in a group namespace which has the default
branch protection disabled.

NOTE: I've made some assumption that this can only happen for the
projects in group namespaces (e.g. project in a user namespace can't
turn the default branch protection off) and that this information about
the disabled default branch protection can always be read from the group
the project is directly assigned to.

Closes #906
CHANGELOG.md Show resolved Hide resolved
@RicePatrick
Copy link
Collaborator

@timofurrer - I tested out a couple scenarios on the GitLab API, and as far as I can tell the default_branch_protection will always come back from the API (even if not explicitly set on the "create" or "update" calls), so I think your assumption is valid.

In the interests of defensive coding for future proofing, would we want to assume a value of 2 (fully protected) if the value is not returned from the API? That's the default value set if nothing is specified in the create/update requests.

@timofurrer
Copy link
Member Author

@PatrickRice-KSC

In the interests of defensive coding for future proofing, would we want to assume a value of 2 (fully protected) if the value is not returned from the API?

What do you mean by "not returned from the API?" ? From the client.Groups.GetGroup() call? I think at the moment we kinda do that if the Namespace.Kind is not group. If GetGroup() fails though I think that should be a hard failure and we shouldn't assume anything.

@RicePatrick
Copy link
Collaborator

@timofurrer - Sorry, what I meant is if we get a valid response from client.Groups.GetGroup() but where the default_branch_protection is not returned. Which would result in a nil value from the group.DefaultBranchProtection attribute.

I'm talking myself out of it though, because that would cause the branch to then trigger the WaitForState loop, which is exactly the behavior we'd want if it was falling back to the default. Nevermind 😄

Copy link
Collaborator

@armsnyder armsnyder left a comment

Choose a reason for hiding this comment

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

Thanks for the test! I agree with your assumptions. I did not check what happens if you have a project within a subgroup of another group, but I would assume the default branch protection settings does not cascade.

@timofurrer timofurrer merged commit 278f2b3 into gitlabhq:main Mar 2, 2022
@github-actions
Copy link

github-actions bot commented Mar 2, 2022

This functionality has been released in v3.11.1 of the Terraform GitLab Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue. Thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants