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
Comments
I was looking for the same feature... is it possible to "Add deployment branch rule"? |
Same for me. I also need to set a branch name/pattern and don't now how to do it. |
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 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 |
The API document specify the following:
So I guess this makes it hard to be added to the terraform module. |
I added a comment in GitHub's product discussions to try to elevate this to their PM team: community/community#14190 (comment) |
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. |
If that's true, that's great news. I'd be happy to review/test/merge a PR to cover this behavior! |
Would really like to see this implemented. Having a custom_branch_policies attribute feels a bit misleading since it's only a bool. |
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 🥳 . |
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. |
Thank you @GMartinez-Sisti and @ilmax! @ilmax I like your suggestion of the separate resource! |
@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 |
Looks like the endpoint went out in v50.0.0 of the SDK |
Yes, wanted to write the same. @kfcampbell any objections about updating to v50? |
@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! |
Great to see a PR near being merged for this, definitely a very desired feature! Thank you |
Affected Resource(s)
Terraform Configuration Files
In the GitHub console, when
custom_branch_policies
is set totrue
, 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?The text was updated successfully, but these errors were encountered: