diff --git a/github/resource_github_repository_environment.go b/github/resource_github_repository_environment.go index 7041e94f13..318159c989 100644 --- a/github/resource_github_repository_environment.go +++ b/github/resource_github_repository_environment.go @@ -232,6 +232,12 @@ func resourceGithubRepositoryEnvironmentRead(ctx context.Context, d *schema.Reso return diag.FromErr(err) } + // Default prevent_self_review to false; it will be overwritten if the + // required_reviewers protection rule is present in the API response. + if err := d.Set("prevent_self_review", false); err != nil { + return diag.FromErr(err) + } + for _, pr := range env.ProtectionRules { switch pr.GetType() { case "wait_timer": @@ -264,7 +270,7 @@ func resourceGithubRepositoryEnvironmentRead(ctx context.Context, d *schema.Reso return diag.FromErr(err) } - if err = d.Set("prevent_self_review", pr.PreventSelfReview); err != nil { + if err = d.Set("prevent_self_review", pr.GetPreventSelfReview()); err != nil { return diag.FromErr(err) } } diff --git a/github/resource_github_repository_environment_test.go b/github/resource_github_repository_environment_test.go index 410ac61586..d14a4286bf 100644 --- a/github/resource_github_repository_environment_test.go +++ b/github/resource_github_repository_environment_test.go @@ -243,7 +243,7 @@ resource "github_repository_environment" "test" { }) }) - t.Run("import", func(t *testing.T) { + t.Run("import_without_reviewers", func(t *testing.T) { t.Parallel() randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) @@ -272,10 +272,12 @@ resource "github_repository_environment" "test" { }, }, { + // The API omits required_reviewers when none are configured, but + // prevent_self_review must still be populated during import. ResourceName: "github_repository_environment.test", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"can_admins_bypass", "prevent_self_review", "reviewers", "wait_timer", "deployment_branch_policy"}, + ImportStateVerifyIgnore: []string{"can_admins_bypass", "reviewers", "wait_timer", "deployment_branch_policy"}, }, }, })