-
Notifications
You must be signed in to change notification settings - Fork 762
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
Fix restrict pushes on github_branch_protection. Fix branch protection tests #2045
Fix restrict pushes on github_branch_protection. Fix branch protection tests #2045
Conversation
@kfcampbell Is there any chance anyone might look at my PR? |
@georgekaz Sorry for the delays, the holidays have been a slow time. I love the fixes here and I'd love to get them into our next major version, which we're targeting for this month. However, we can't release as-is without state migration, otherwise users are going to be annoyed when their state doesn't work with the new version. We have some examples in our codebase (search for |
@kfcampbell I'll work on that now. If we're upgrading state, do you have any thoughts on changing the name of the existing property from It seems a bit odd to have So from:
to:
I'll understand if you prefer not to but I thought I should mention it. |
The work around the state migration has been pretty confusing. I've figured out that this provider is still using v1 of the terraform-plugin-sdk and I can see that the version in my state file is version 4 which is TF 0.11 compatible despite the fact I'm using TF v1.6.4. So it seems like I need to use the advice from Terraform v0.11 SDK State Migrations but there's an existing state migration that is using the Terraform v0.12 SDK State Migrations in the branch protection func here. To further confuse matters, the docs say:
Other resources such as resource_github_repository.go are using the MigrateState implementation. I suppose I should add to the existing migration style that has already been used in resource_github_branch_protection.go |
545e983
to
7f24a54
Compare
@kfcampbell I've added the commit. I've tested it locally and it seems to work but honestly I'm not sure it's doing anything because even after running it, the "schema_version" remains at 1 in the state file. There are no errors though when going from the old schema to the new one and the plan works. As long as things are moved from the old format to the new one, it works. |
I see you have your own PR #1780 @kfcampbell to upgrade to sdk v2. With that in place, the state migration I've done would be the correct one for sure. |
📓 I've changed the base of this PR to our
I like this change! I'd be happy to have this go in at the same time.
I totally agree; this part of the project is pretty obnoxious to deal with. That sounds like a good idea to me! |
I'm going to look at #1780 tomorrow and see if I can get it into a little bit better shape, and that might guide us on the migration issue here. |
042b0f2
to
811cfcb
Compare
ok that's now changed from push_restrictions to push_allowances. I also did some further testing on the state migration and made a fix and have confirmed it works. The schema_version on the object is now incrementing as expected. |
@georgekaz thanks for the work here! I've updated the Hashicorp SDK. Would you mind merging the changes from the v6 branch and validating one more time? Then we can get this in and the major change released, which is exciting! |
Change blocks_creations default to true. Fix broken build.
8d015db
to
bf724a2
Compare
@kfcampbell that's rebased on v6, fixed and tested. However I've found a new problem, unrelated to my changes. Some of the tests in
and when these tests are enabled I get the error:
I don't think you need more of that stack trace. It seems that something else has broken the data source for github user. Running I've not dived into this but my guess is that it's the |
@georgekaz thanks! Running on the main branch, tests (
Running those tests on the Running the same tests ( This is a somewhat obnoxious situation, as the default is broken but arguably less broken than our two more updated scenarios (this branch and |
hmm. Well most of the branch protection tests were failing when I started out this work and I made all the v4 ones pass on my branch. I tried not to get involved with any of the others. I think the panic is most likely related to the sdk upgrade because it's going to be the biggest change, or the recent upgrade to github go lib v57. Have you run those same tests just on the sdk upgrade branch? I would target the tests on that data rather than the branch protection ones which are failing as a consequence of that.
It requires GITHUB_OWNER and/or GITHUB_ORGANISATION to be set in order to see the error I'll take a look and see what I can do |
@kfcampbell I managed to fix the branch protection and user tests, please see my last commit. I also checked for other timestamp fields that weren't being cast and I found the ones on release. Even after fixing the code, the user tests were failing because it assumed that a |
@georgekaz you rock! This fixes nearly all the branch protection tests; I see that Are you ready for this to go into the v6 branch? I can cut another beta version for that release afterward. |
thanks @kfcampbell . Both those tests pass for me, do you have the env vars set?
I think this problem is fixed and it's ready to merge, although feel free to cut another beta first if you prefer. I do think a separate task to review all the tests is probably in required. As I say, when I started working on this hardly any of the existing branch protection tests were passing and I had to fix all those. It now seems that the user data tests weren't reliable either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the work here! I'll cut one more v6.0.0-release-candidate branch, and shoot to merge the v6 branch into main soon.
Also, I really really appreciate all the love and attention paid to fixing our tests here. Thanks a bunch! |
* Add retryable transport for errors (#1704) * Add retryable transport for errors In order to address the issue #210 I have added 3 new parameters to the provider - retry_delay_ms - max_retries - retryable_errors In case max_retries is > 0 (defaults to zero) it will retry the request in case it is an error the retryable_errors defaults to [500, 502, 503, 504] It retries after the ms specified in retry_delay_ms (defaults to 1000) * Update documentation with new parameters for retry * Change default of max_retries to 3 * Fix typo in naming * Update github/transport_test.go * Add error check for data seek * Consolidate the default retriable errors on a function * Fix typo on the comments Co-authored-by: Keegan Campbell <[email protected]> * Update vendor * Fix merging conflicts * Update documentation with new parameters for retry * Change default of max_retries to 3 * Fix typo in naming * Add error check for data seek * Update github/transport_test.go * Consolidate the default retriable errors on a function * Fix typo on the comments Co-authored-by: Keegan Campbell <[email protected]> * Don't run go mod tidy on release (#1788) * Don't run go mod tidy on release * Be more specific about releases * Fix lint with APIMeta deprecation --------- Co-authored-by: Keegan Campbell <[email protected]> Co-authored-by: Nick Floyd <[email protected]> * fix: remove repository topic from state if it doesnt exist in GitHub anymore (#1918) * remove repository topic if they cannot be found in GitHub anymore * Fix build error by bumping package version in offending file --------- Co-authored-by: Keegan Campbell <[email protected]> * Bump version to v6 (#2106) * Upgrade to Terraform Plugin SDK v2 (#1780) * go mod tidy -go=1.16 && go mod tidy -go=1.17 * Run go mod vendor * Attempt v2 upgrade * Plugin compiling * Fix some provider test errors * Fix test compilation error * ValidateFunc --> ValidateDiagFunc * Fix casing * Sprinkle toDiagFunc everywhere * More fixes for validation functions * State --> StateContext * %s --> %v when printing diags * ConfigureFunc --> ConfigureContextFunc * Checking results of d.Set, round one * Continue checking d.Set results * Check results of d.Set, round three * Checking d.Set results, round four * d.Set round five * In tests, export GITHUB_TEST_ORGANIZATION * Remove unnecessary MaxItems on computed value * Go build now works * Resolve linting errors * Apply diag.FromErr twice more * Pass key names into toDiagFunc helper * Construct cty.Path from strings * Tests now working * Update terraform-plugin-sdk version * Remove commented attribute setting in resource_github_team.go * Fix restrict pushes on github_branch_protection. Fix branch protection tests (#2045) * Update restrict pushes. Fix branch protection tests Change blocks_creations default to true. Fix broken build. * add state migration * rename push_restrictions to push_allowances * correct state migration issue * add docs clarification * update migration func args * fix test args * cleanup tests * Pass context.Background() in test * fix timestamp fields --------- Co-authored-by: Keegan Campbell <[email protected]> * Set group_id correctly (#2133) * Run go get -u github.com/golangci/golangci-lint * Separate github_team_members import from github_team as create_default_maintainers is not defined for members resource (#2126) Co-authored-by: Keegan Campbell <[email protected]> * Add missing variable definition for test case --------- Co-authored-by: Daniel França <[email protected]> Co-authored-by: Nick Floyd <[email protected]> Co-authored-by: Felix Luthman <[email protected]> Co-authored-by: georgekaz <[email protected]> Co-authored-by: Rich Young <[email protected]>
…Github Looks like this PR: integrations/terraform-provider-github#2045 introduced a breaking change in the v6.0.0 release of the Terraform provider for GitHub. No note of breaking changes on the release page but it was a major release so breaking changes are likely. https://github.com/integrations/terraform-provider-github/releases/tag/v6.0.0
BREAKING CHANGE: `push_restrictions` argument is replaced by `restrict_pushes` (Check integrations/terraform-provider-github#2045 for more details)
BREAKING CHANGE: `push_restrictions` argument is replaced by `restrict_pushes` (Check integrations/terraform-provider-github#2045 for more details)
Resolves #594
Before the change?
blocks_creations
which currently does not work unless you also setpush_restrictions
with some values.restrictsPushes
,blocksCreations
andpushAllowances
. Currently setting a value for pushAllowances (push_restrictions) also enables restrictsPushes, which makes this impossible to fix without creating a breaking change or a change that will result in options fighting for control of the same properties and therefore there always being planned changes (similar to howrestrict_dismissals
anddismissal_restrictions
fight over the same API object calledrestrictsReviewDismissals
).TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubBranchProtection
matched both the test suite for the graph api and for the rest api (v3) version.[DEBUG] Problem setting 'require_last_push_approval' in X Y branch protection (Z)
After the change?
you now use
NOTE: It's tempting to rename
push_restrictions
topush_allowances
to match the API (pushAllowances) and to make more sense, or topush_bypassers
orrestrict_pushes_bypassers
to match similar exiting options such aspull_request_bypassers
&force_push_bypassers
which map tobypassPullRequestAllowances
andbypassForcePushAllowances
respectively.This represents the API and the GUI better:
TF_LOG=DEBUG TF_ACC=1 go test -v ./... -run ^TestAccGithubBranchProtectionV4
to avoid running the TestAccGithubBranchProtectionV3 testsPull request checklist
Does this introduce a breaking change?
This introduces a breaking change because there was no way to fix the current bug without creating a breaking change.
The impact is that people will need to move their existing
push_restrictions
lists inside ofrestrict_pushes{}
.Please see our docs on breaking changes to help!