diff --git a/github/resource_github_repository_environment.go b/github/resource_github_repository_environment.go index 171af8a74f..4d93a14924 100644 --- a/github/resource_github_repository_environment.go +++ b/github/resource_github_repository_environment.go @@ -39,6 +39,12 @@ func resourceGithubRepositoryEnvironment() *schema.Resource { Default: true, Description: "Can Admins bypass deployment protections", }, + "prevent_self_review": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Prevent users from approving workflows runs that they triggered.", + }, "wait_timer": { Type: schema.TypeInt, Optional: true, @@ -170,6 +176,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf "users": users, }, }) + + d.Set("prevent_self_review", pr.PreventSelfReview) } } @@ -233,6 +241,8 @@ func createUpdateEnvironmentData(d *schema.ResourceData, meta interface{}) githu data.CanAdminsBypass = github.Bool(d.Get("can_admins_bypass").(bool)) + data.PreventSelfReview = github.Bool(d.Get("prevent_self_review").(bool)) + if v, ok := d.GetOk("reviewers"); ok { envReviewers := make([]*github.EnvReviewers, 0) diff --git a/github/resource_github_repository_environment_test.go b/github/resource_github_repository_environment_test.go index 2b0ed07db9..afa83b8936 100644 --- a/github/resource_github_repository_environment_test.go +++ b/github/resource_github_repository_environment_test.go @@ -30,6 +30,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) { environment = "environment / test" can_admins_bypass = false wait_timer = 10000 + prevent_self_review = true reviewers { users = [data.github_user.current.id] } @@ -44,6 +45,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) { check := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment / test"), resource.TestCheckResourceAttr("github_repository_environment.test", "can_admins_bypass", "false"), + resource.TestCheckResourceAttr("github_repository_environment.test", "prevent_self_review", "true"), resource.TestCheckResourceAttr("github_repository_environment.test", "wait_timer", "10000"), ) diff --git a/website/docs/r/repository_environment.html.markdown b/website/docs/r/repository_environment.html.markdown index fc9da4fd5c..69b3cd2474 100644 --- a/website/docs/r/repository_environment.html.markdown +++ b/website/docs/r/repository_environment.html.markdown @@ -17,18 +17,19 @@ data "github_user" "current" { } resource "github_repository" "example" { - name = "A Repository Project" - description = "My awesome codebase" + name = "A Repository Project" + description = "My awesome codebase" } resource "github_repository_environment" "example" { - environment = "example" - repository = github_repository.example.name + environment = "example" + repository = github_repository.example.name + prevent_self_review = true reviewers { users = [data.github_user.current.id] } deployment_branch_policy { - protected_branches = true + protected_branches = true custom_branch_policies = false } } @@ -46,6 +47,8 @@ The following arguments are supported: * `can_admins_bypass` - (Optional) Can repository admins bypass the environment protections. Defaults to `true`. +* `prevent_self_review` - (Optional) Whether or not a user who created the job is prevented from approving their own job. Defaults to `false`. + ### Reviewers The `reviewers` block supports the following: