Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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