fix: prevent inconsistent final plan for prevent_self_review in github_repository_environment - #3583
Conversation
|
👋 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. |
|
Nice, thanks! Could you add a regression acceptance test case as well? |
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.
|
@deiga Have added the test. Can you kindly review? |
|
@deiga Have resolved your PR review feedback. Can you kindly check once? |
|
@kishaningithub I ran your test without any other code changes and the test doesn't fail. Can you please provide DEBUG level logs of the issue you are trying to resolve here? |
|
@deiga The issue was with the test The original test did not reproduce the issue because it asserted the value immediately after creation. At that point, the schema default had already populated The failing scenario is a refresh/read from imported or legacy state where I replaced the test with a read-path regression test that starts with the attribute absent from state and mocks that API response. The corrected test fails without the production change and passes with it. I also removed |
| t.Run(test.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ts := githubApiMock([]*mockResponse{ |
There was a problem hiding this comment.
issue: no mocked tests inside TestAcc functions.
We need an acceptance test against the real API to verify the behaviour you mention.
There was a problem hiding this comment.
@deiga The code now much simpler. The acceptance test "import_without_reviewers" fails when the fix is not present
b0a5831 to
7aaf5ec
Compare
…b_repository_environment
…nd use test helper
7aaf5ec to
8ec4533
Compare
|
@deiga This is the exact scenario.. I have a state which is like this Result of
|
|
@deiga Given the above context. Which route do you think i must take for the fix? Any suggestions? |
|
@kishaningithub Please provide a testcase that reproduces your error-case and/or DEBUG level logs if the apply run |
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!