Skip to content

Commit

Permalink
Add feature can_admins_bypass for repo environments | fixed wait_time…
Browse files Browse the repository at this point in the history
…r issue for repo environments (#2001)

* fix environment wait timer so GitHub stays in line with terraform

* add abilty to use can_admins_bypass for environment protections

* update docs for repository environment can_admins_bypass

* refactored wait_timer code as the logic was broken in a previous commit for this PR

---------

Co-authored-by: Keegan Campbell <[email protected]>
  • Loading branch information
scott-doyland-burrows and kfcampbell authored Nov 21, 2023
1 parent 0b984fb commit 4cf3adb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions github/resource_github_repository_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func resourceGithubRepositoryEnvironment() *schema.Resource {
ForceNew: true,
Description: "The name of the environment.",
},
"can_admins_bypass": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Can Admins bypass deployment protections",
},
"wait_timer": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -134,6 +140,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf

d.Set("repository", repoName)
d.Set("environment", envName)
d.Set("wait_timer", nil)
d.Set("can_admins_bypass", env.CanAdminsBypass)

for _, pr := range env.ProtectionRules {
switch *pr.Type {
Expand Down Expand Up @@ -223,6 +231,8 @@ func createUpdateEnvironmentData(d *schema.ResourceData, meta interface{}) githu
data.WaitTimer = github.Int(v.(int))
}

data.CanAdminsBypass = github.Bool(d.Get("can_admins_bypass").(bool))

if v, ok := d.GetOk("reviewers"); ok {
envReviewers := make([]*github.EnvReviewers, 0)

Expand Down
13 changes: 7 additions & 6 deletions github/resource_github_repository_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
resource "github_repository" "test" {
name = "tf-acc-test-%s"
visibility = "public"
}
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
wait_timer = 10000
can_admins_bypass = false
wait_timer = 10000
reviewers {
users = [data.github_user.current.id]
}
Expand All @@ -39,11 +41,10 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
`, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository_environment.test", "environment",
"environment/test",
),
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", "wait_timer", "10000"),
)

testCase := func(t *testing.T, mode string) {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/repository_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The following arguments are supported:

* `wait_timer` - (Optional) Amount of time to delay a job after the job is initially triggered.

* `can_admins_bypass` - (Optional) Can repository admins bypass the environment protections. Defaults to `true`.

### Reviewers

The `reviewers` block supports the following:
Expand Down

0 comments on commit 4cf3adb

Please sign in to comment.