fix: prevent inconsistent final plan for prevent_self_review in github_repository_environment - #3583
Open
kishaningithub wants to merge 2 commits into
Open
Conversation
…b_repository_environment
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
Collaborator
|
Nice, thanks! Could you add a regression acceptance test case as well? |
Contributor
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used.
Fixes prevent_self_review state normalization when GitHub omits reviewer protection data.
Changes:
- Defaults
prevent_self_reviewstate tofalse. - Safely handles a nil API value.
Author
|
@deiga Have added the test. Can you kindly review? |
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.
Fixes an issue where Terraform reports "Provider produced inconsistent final plan" for the
prevent_self_reviewattribute ongithub_repository_environmentresources that have no reviewers configured.Resolves a missed edge case in #1967
Problem
When an environment has no reviewers, the GitHub API does not return a
required_reviewersprotection rule. The read function only setprevent_self_reviewinside thecase "required_reviewers"branch, so the attribute was never written to state—leaving it asnull. Terraform's plan expectedfalse(the schema default), causing the following mismatch:Error: Provider produced inconsistent final plan .prevent_self_review: was cty.False, but now null.
Root Cause
prevent_self_reviewwas only set in state when arequired_reviewersprotection rule existed in the API response.pr.PreventSelfReview(a*bool) was passed directly tod.Set()without nil-checking, which could also storenullin state.Fix
prevent_self_reviewtofalsebefore iterating protection rules, ensuring it always has a value in state.pr.PreventSelfReviewwith a nil guard, defaulting tofalse.Testing
Environments without reviewers (the failing case) are already exercised by the
create_with_id_separator_in_nameandupdate_to_add_reviewersacceptance tests which create environments with no initial reviewers.Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!