terraform-provider-github: Repository environment creation error
Terraform Version
Terraform v1.0.7
Affected Resource(s)
github_repository_environment
Terraform Configuration Files
resource "github_repository_environment" "my_repo_environments" {
for_each = toset([
"production",
"staging",
])
repository = github_repository.my_repo.name
environment = each.key
}
Debug Output
Expected Behavior
Create an environment
Actual Behavior
Got this errore (both staging and production)
╷
│ Error: PUT https://api.github.com/repos/my-org/my-repo/environments/production: 422 Fail to create protected rule, please ensure billing plan include protected branch gate. []
│
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
Work arround
If I set the “Deployment branches” in the GUI (protected branches), import the resource and add the following config terraform terminates well.
deployment_branch_policy {
protected_branches = true
custom_branch_policies = false
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 19 (8 by maintainers)
Relevant Terraform provider Go file: https://github.com/integrations/terraform-provider-github/blame/main/vendor/github.com/google/go-github/v47/github/repos_environments.go Line 147-172
Seems due to this being a new feature for GitHub Teams when the relevant Terraform provider code was written they didn’t count for a use case where a user would want to create environments but have no access to the branch protection rule feature.
@kfcampbell got a PR out in
go-githubto fix the issue. Once it’s merged we just have to upgrade the package here and it should work 🙂For what it’s worth. We are also facing this issue in our company.
I used the http-full provider to try to have this as automated as possible (terraform’s http provider does not support put)
Then, in my secrets I have
Its not ideal, but it helps
We’re also struggling with this. The environments do get created, but tf errors out with a 422 each time, so state is not updated.