Skip to content

fix: prevent inconsistent final plan for prevent_self_review in github_repository_environment - #3583

Open
kishaningithub wants to merge 2 commits into
integrations:mainfrom
kishaningithub:fix-prevent-self-review-no-reviewers
Open

fix: prevent inconsistent final plan for prevent_self_review in github_repository_environment#3583
kishaningithub wants to merge 2 commits into
integrations:mainfrom
kishaningithub:fix-prevent-self-review-no-reviewers

Conversation

@kishaningithub

@kishaningithub kishaningithub commented Jul 28, 2026

Copy link
Copy Markdown

Fixes an issue where Terraform reports "Provider produced inconsistent final plan" for the prevent_self_review attribute on github_repository_environment resources 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_reviewers protection rule. The read function only set prevent_self_review inside the case "required_reviewers" branch, so the attribute was never written to state—leaving it as null. Terraform's plan expected false (the schema default), causing the following mismatch:

Error: Provider produced inconsistent final plan .prevent_self_review: was cty.False, but now null.

Root Cause

  1. prevent_self_review was only set in state when a required_reviewers protection rule existed in the API response.
  2. pr.PreventSelfReview (a *bool) was passed directly to d.Set() without nil-checking, which could also store null in state.

Fix

  • Set prevent_self_review to false before iterating protection rules, ensuring it always has a value in state.
  • Safely dereference pr.PreventSelfReview with a nil guard, defaulting to false.

Testing

Environments without reviewers (the failing case) are already exercised by the create_with_id_separator_in_name and update_to_add_reviewers acceptance tests which create environments with no initial reviewers.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions

Copy link
Copy Markdown

👋 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.

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Jul 28, 2026
@deiga deiga added r/repository_environment Status: Triage This is being looked at and prioritized labels Jul 28, 2026
@deiga
deiga requested a review from Copilot July 28, 2026 16:51
@deiga

deiga commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Nice, thanks! Could you add a regression acceptance test case as well?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_review state to false.
  • Safely handles a nil API value.

Comment thread github/resource_github_repository_environment.go
@kishaningithub

Copy link
Copy Markdown
Author

@deiga Have added the test. Can you kindly review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r/repository_environment Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants