Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set branch names/patterns when custom_branch_policies is true. #922

Closed
Omicron7 opened this issue Oct 4, 2021 · 17 comments · Fixed by #1799
Closed

Unable to set branch names/patterns when custom_branch_policies is true. #922

Omicron7 opened this issue Oct 4, 2021 · 17 comments · Fixed by #1799
Labels
r/repository_environment Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request

Comments

@Omicron7
Copy link

Omicron7 commented Oct 4, 2021

Affected Resource(s)

  • github_repository_environment

Terraform Configuration Files

resource "github_repository_environment" "environment" {
  repository  = "repository_name"
  environment = "testing"

  deployment_branch_policy {
    protected_branches     = false
    custom_branch_policies = true
  }
}

In the GitHub console, when custom_branch_policies is set to true, it allows setting one or more Branch names/patterns to match against. It doesn't seem like this is possible in Terraform. I'm unable to find any other GitHub resource that would allow managing that list per environment. Am I missing something?

@bishwash-delphix
Copy link

I was looking for the same feature... is it possible to "Add deployment branch rule"?

@gilfthde
Copy link

Same for me. I also need to set a branch name/pattern and don't now how to do it.

@figadore
Copy link

figadore commented Dec 21, 2021

Agree, seems like there should be a way to specify the patterns that can deploy to the environment. Maybe something like

resource "github_repository_environment" "default" {
  repository  = var.repo
  environment = "${var.env_id}"
  reviewers {
    teams = var.reviewers_team
    users = []
  }
  deployment_branch_policy {
    protected_branches          = false
    custom_branch_policies = true
    custom_branch_regex = ["main"]
  }
}

?

It doesn't look like the go-github package supports this at the moment
https://github.com/google/go-github/blob/7add3a89d10dbdcbbfab71036aa9c12e5ee997c8/github/repos_environments.go#L42

Edit: digging deeper, there isn't much else even documented for the API at https://docs.github.com/en/rest/reference/deployments#create-or-update-an-environment

Related: https://stackoverflow.com/questions/69697460/create-deployment-branch-rule-with-github-rest-api

@pasdam
Copy link

pasdam commented Jan 13, 2022

The API document specify the following:

Note: Although you can use this operation to specify that only branches that match specified name patterns can deploy to this environment, you must use the UI to set the name patterns. For more information, see "Environments."

So I guess this makes it hard to be added to the terraform module.

@StephenWithPH
Copy link

I added a comment in GitHub's product discussions to try to elevate this to their PM team: community/community#14190 (comment)

@StephenWithPH
Copy link

https://github.com/orgs/community/discussions/14190#discussioncomment-3931426 points to https://docs.github.com/en/rest/deployments/branch-policies#create-a-deployment-branch-policy, which suggests that there is now an API endpoint for this.

@kfcampbell
Copy link
Member

If that's true, that's great news. I'd be happy to review/test/merge a PR to cover this behavior!

@nickfloyd nickfloyd added the Status: Triage This is being looked at and prioritized label Oct 31, 2022
@nickfloyd nickfloyd assigned nickfloyd and unassigned nickfloyd Nov 7, 2022
@nickfloyd nickfloyd added Priority: Normal and removed Status: Triage This is being looked at and prioritized labels Nov 7, 2022
@mBlomsterberg
Copy link

Would really like to see this implemented. Having a custom_branch_policies attribute feels a bit misleading since it's only a bool.

@kfcampbell kfcampbell added the Status: Up for grabs Issues that are ready to be worked on by anyone label Dec 6, 2022
@romikoops
Copy link

Really disappointing that we still do not have it. If we automate something, it should have 100% automation, not 99 and etc.

@GMartinez-Sisti
Copy link

Really disappointing that we still do not have it. If we automate something, it should have 100% automation, not 99 and etc.

@romikoops this is an on going project, as is the Github API, something will always be missing. This issue is "Up for grabs" if you want to contribute.

On the other hand, turn it around, it's great that we have 99% automation for Github using terraform 🥳 .

@ilmax
Copy link
Contributor

ilmax commented Jan 13, 2023

Support in the go-github SDK has been merged recently here, unfortunately is not part of the latest version of the SDK (49.1.0 at the moment) so we may probably wait until that's released.

Was also thinking if this should end up in a separate resource similar to the following:

resource "github_repository_environment_deployment_branch_policy" "default" {
  repository  = var.repo
  environment = "${var.env_id}"
  pattern = "main"
}

rather than the suggested

resource "github_repository_environment" "default" {
  repository  = var.repo
  environment = "${var.env_id}"
  reviewers {
    teams = var.reviewers_team
    users = []
  }
  deployment_branch_policy {
    protected_branches          = false
    custom_branch_policies = true
    custom_branch_regex = ["main"]
  }
}

Due to the fact that's exposed via a different api than the repository environment.

@kfcampbell
Copy link
Member

Thank you @GMartinez-Sisti and @ilmax!

@ilmax I like your suggestion of the separate resource!

@ilmax
Copy link
Contributor

ilmax commented Jan 13, 2023

@kfcampbell then I may give it a try as soon as the afk is released.

Disclaimer: I am not really expert in go though but with copy paste and some help from the PR review I should be able to land this

@justin-kidman-axomic
Copy link

Looks like the endpoint went out in v50.0.0 of the SDK

@ilmax
Copy link
Contributor

ilmax commented Jan 27, 2023

Yes, wanted to write the same. @kfcampbell any objections about updating to v50?

@kfcampbell
Copy link
Member

@ilmax My vote would be to do so in a separate PR than the feature one. I have no reservations about updating to the latest version though!

@jjgriff93
Copy link

Great to see a PR near being merged for this, definitely a very desired feature! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r/repository_environment Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request
Projects
None yet