Skip to content

Conversation

RicePatrick
Copy link
Collaborator

@RicePatrick RicePatrick commented Feb 11, 2022

This fixes an issue where branch protection ran in the background when creating a project, causing the default branch to occasionally not be protected.

Description

Closes #800
There was a race condition apparent in project creation where occasionally the branch protection would return false even though the branch had been protected asynchronously. This could cause issues if downstream resources used that output value. This also caused several tests that checked the branch protection status to be flakey and seemingly appear to fail rendomly when they were, in fact, failing properly.

PR Checklist

  • Resource attributes match 1:1 the names and structure of the API resource in the GitLab API documentation.
  • Examples are updated with:
    • A *.tf file for the resource/s with at least one usage example
    • A *.sh file for the resource/s with an import example (if applicable)
  • New resources have at minimum a basic test with three steps:
    • Create the resource
    • Update the attributes
    • Import the resource
  • No new //lintignore comments that came from copied code. Linter rules are meant to be enforced on new code.

This fixes an issue where branch protection running in the background, causing the default branch to occasionally not be protected.
@github-actions github-actions bot added provider resource Adds or modifies a resource size/S labels Feb 11, 2022
@RicePatrick
Copy link
Collaborator Author

OK, well this is embarrassing given I'd run those tests locally. Investigating.

@RicePatrick
Copy link
Collaborator Author

OK, note to self. Don't forget when running make testacc locally to remove the limiter you put on it to only run your specific tests. Whoops.

The issue here was that if you don't set default_branch or initialize_with_readme, then the default branch obviously throws a 404 when you attempt to query it. Similar to other situations where this happens, I now catch the 404 status and exit the WaitForState loop.

I'm oddly still getting one failing test with this change, related to a data source for an archived project not returning an empty state. I wouldn't have changed that behavior I'd think, but I'm going to go ahead and commit the changes for tonight and keep looking at it tomorrow.

This can happen when default_branch or initialize_with_readme are not set (or the initialize is set to false explicitly) as the branch doesn't exist until first commit.
@github-actions github-actions bot added size/M and removed size/S labels Feb 13, 2022
@timofurrer timofurrer dismissed armsnyder’s stale review February 13, 2022 16:15

Hey Adam, I'm trying to "dismiss your review" in hope that I'm able to merge :D Thanks 🍻

@timofurrer timofurrer merged commit 9cb5889 into gitlabhq:main Feb 13, 2022
@timofurrer
Copy link
Member

@PatrickRice-KSC thanks for the deep-dive into what caused this and thanks for the fix! Much appreciated 🎉

@armsnyder armsnyder added this to the v3.10.0 milestone Feb 14, 2022
@github-actions
Copy link

This functionality has been released in v3.10.0 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!

@RicePatrick RicePatrick deleted the fix_flakey_project_resource branch May 9, 2022 02:06
@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.

Labels

provider resource Adds or modifies a resource size/M

Development

Successfully merging this pull request may close these issues.

3 participants