You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Jarek Rodak, Vivek, Jean Prat, Ville Sebastian Olsson, Konrad Bloor, Sylvain, Abdelkader Boudih, Novikov Sergey, Maximilian Hippler, Nikolai Fauskrud and 1 more
// MarshalJSON implements the json.Marshaler interface.
// As the only way to clear a WaitTimer is to set it to 0, a missing WaitTimer object should default to 0, not null.
func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) {
type Alias CreateUpdateEnvironment
if c.WaitTimer == nil {
c.WaitTimer = Int(0)
}
return json.Marshal(&struct {
*Alias
}{
Alias: (*Alias)(c),
})
}
// CreateUpdateEnvironment represents the fields required for the create/update operation
// following the Create/Update release example.
// See https://github.com/google/go-github/issues/992 for more information.
// Removed omitempty here as the API expects null values for reviewers and deployment_branch_policy to clear them.
type CreateUpdateEnvironment struct {
WaitTimer *int `json:"wait_timer"`
Reviewers []*EnvReviewers `json:"reviewers"`
DeploymentBranchPolicy *BranchPolicy `json:"deployment_branch_policy"`
}
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.
Reacted by ti-atlastechnol, Oliver Höhn, Jarek Rodak, geertn, Kasparas Antanas Krivas and Vivek
Because it only fails on create/update you can create the environments manually or via API (we had quite a few to create, so we opted for this, very straightforward to use) and then import the environments into your code.
Obviously this is not a long term solution, but can work if the missing feature is blocking you.
@AnitaErnszt what version are you importing with? I'm also impacted by this 422 Fail to create protected rule to create the environment and then finally add some secrets to it. I created the environment through the UI manually, but every time I import, it fails with the following:
Stack trace from the terraform-provider-github_v5.2.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0x19f7eb0]
goroutine 64 [running]:
github.com/integrations/terraform-provider-github/v5/github.resourceGithubRepositoryEnvironmentRead(0xc0002288c0, {0x1a86d00?, 0xc00013ab80?})
github.com/integrations/terraform-provider-github/v5/github/resource_github_repository_environment.go:125 +0x490
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000781d60, 0xc000181d10, {0x1a86d00, 0xc00013ab80})
github.com/hashicorp/[email protected]/helper/schema/resource.go:470 +0x1aa
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc000116a50, {0xc00058d0e0?, 0x10b3ba6?}, 0xc00058d0e0)
github.com/hashicorp/[email protected]/internal/helper/plugin/grpc_provider.go:535 +0x34b
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler({0x1c2a1c0?, 0xc000116a50}, {0x1e89730, 0xc00017a120}, 0xc00058d080, 0x0)
github.com/hashicorp/[email protected]/internal/tfplugin5/tfplugin5.pb.go:3269 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002b0380, {0x1e8cea0, 0xc000682340}, 0xc00097a6c0, 0xc0003acc30, 0x2534710, 0x0)
google.golang.org/[email protected]/server.go:1283 +0xcfd
google.golang.org/grpc.(*Server).handleStream(0xc0002b0380, {0x1e8cea0, 0xc000682340}, 0xc00097a6c0, 0x0)
google.golang.org/[email protected]/server.go:1620 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/[email protected]/server.go:922 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/server.go:920 +0x28a
Error: The terraform-provider-github_v5.2.0 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
@0xbigboss I have managed to reproduce this error when the credentials were invalid (expired in my case, but I assume it returns the same error for any invalid cred)
We're still using 4.26, but I just tested with 5.2.0 and works
I note that I can reproduce this error with valid credentials, and where we are able to update the custom branch rules via the web UI (meaning we have sufficient account privileges). Trying various options directly via the API seems to yield the same result.
@richchurcher as I have mentioned before, this issue is with the provider. If you are on GitHub Pro or Teams, you'll face the issue. It's completely unrelated to the creds validity.
It's worth reading the whole tread, I also copied the code snippet that's responsible for the bug.
(On my previous message I was debugging the error raised a message above, trying to help someone to work around the issue with a temporary solution, and is also unrelated to the GitHub issue discussed in the tread)
@kfcampbell I have opened the issue in go-github as the terraform provider uses their struct to make the API call.
They suggested to either add a flag or separate the feature into 2 API endpoints, but not sure how it would work on the provider side:
Is there a meta argument I could access to check the caller's GitHub plan (to decide which API call we should be making)?
I'm looking for something similar to isOrganization on the Owner struct.
An alternative solution can be if we error handle on 422 (aka the original call failed because we don't have enterprise) and make a second API call to the alternative endpoint?
An other, but less elegant solution can be if we let the terraform user decide whether they have the wait_timer feature available. We could add a has_wait_timer attribute to the resource (defaults to true, team/pro users would intentionally have to set this to false), and we add a flag / make API call to the alternative endpoint based on this value.
Is there a meta argument I could access to check the caller's GitHub plan (to decide which API call we should be making)?
There's not anything built into meta unfortunately:
Hmm...there's a GitHub Billing API but it doesn't look like what we're looking for either.
An alternative solution can be if we error handle on 422 (aka the original call failed because we don't have enterprise) and make a second API call to the alternative endpoint?
We do have a precedent for handling 422s like this here. It's definitely a little gross but it would be better than not solving the issue at all.
Activity
AlessandroLorenzi commentedon Aug 26, 2022
ok, so probably is not a terraform problem but github api
ti-atlastechnol commentedon Sep 9, 2022
TLDR; I suppose is
wait_timerparameter that has been sent as 0 even if omited in terraformUsing
github providerI receive the same 422 error: "422 Fail to create protected rule, please ensure billing plan include protected branch gate. []"Debugging a Terraform apply:
wait_timer: 0 was inserted and that causes the error
Using
github apiit works wellI suppose is "wait_timer" parameter that has been sent even if omited, because when I run with this parameter shows the same error
AnitaErnszt commentedon Sep 12, 2022
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.
bas-ie commentedon Sep 18, 2022
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.
avivek commentedon Sep 20, 2022
Is this something that we can expect a quick fix for??
The jobs are left in a failed state always due to this issue.
AnitaErnszt commentedon Sep 20, 2022
There's a work around, this is how we solved it:
Because it only fails on create/update you can create the environments manually or via API (we had quite a few to create, so we opted for this, very straightforward to use) and then import the environments into your code.
Obviously this is not a long term solution, but can work if the missing feature is blocking you.
alleneubank commentedon Sep 22, 2022
@AnitaErnszt what version are you importing with? I'm also impacted by this
422 Fail to create protected ruleto create the environment and then finally add some secrets to it. I created the environment through the UI manually, but every time I import, it fails with the following:AnitaErnszt commentedon Sep 26, 2022
@0xbigboss I have managed to reproduce this error when the credentials were invalid (expired in my case, but I assume it returns the same error for any invalid cred)
We're still using 4.26, but I just tested with 5.2.0 and works
bas-ie commentedon Oct 5, 2022
I note that I can reproduce this error with valid credentials, and where we are able to update the custom branch rules via the web UI (meaning we have sufficient account privileges). Trying various options directly via the API seems to yield the same result.
bas-ie commentedon Oct 5, 2022
See: https://github.com/orgs/community/discussions/30201#discussioncomment-3801138 for API request attempts.
AnitaErnszt commentedon Oct 5, 2022
@richchurcher as I have mentioned before, this issue is with the provider. If you are on GitHub Pro or Teams, you'll face the issue. It's completely unrelated to the creds validity.
It's worth reading the whole tread, I also copied the code snippet that's responsible for the bug.
(On my previous message I was debugging the error raised a message above, trying to help someone to work around the issue with a temporary solution, and is also unrelated to the GitHub issue discussed in the tread)
Hope this helps.
Konubinix commentedon Nov 18, 2022
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
otavioribeiromedeiros commentedon Nov 21, 2022
I don't use any protection rules, I would like to be able to create a new environment like this:
It'd be very useful if Github provider could support it otherwise I'll have to do some workaround.
The following would also help:
kfcampbell commentedon Nov 28, 2022
If anybody has interest in opening up a PR to fix this behavior, I'd be happy to review!
AnitaErnszt commentedon Dec 20, 2022
@kfcampbell I have opened the issue in
go-githubas the terraform provider uses their struct to make the API call.They suggested to either add a flag or separate the feature into 2 API endpoints, but not sure how it would work on the provider side:
Is there a meta argument I could access to check the caller's GitHub plan (to decide which API call we should be making)?
I'm looking for something similar to isOrganization on the Owner struct.
An alternative solution can be if we error handle on 422 (aka the original call failed because we don't have enterprise) and make a second API call to the alternative endpoint?
An other, but less elegant solution can be if we let the terraform user decide whether they have the
wait_timerfeature available. We could add ahas_wait_timerattribute to the resource (defaults to true, team/pro users would intentionally have to set this to false), and we add a flag / make API call to the alternative endpoint based on this value.kfcampbell commentedon Jan 3, 2023
There's not anything built into
metaunfortunately:Hmm...there's a GitHub Billing API but it doesn't look like what we're looking for either.
We do have a precedent for handling 422s like this here. It's definitely a little gross but it would be better than not solving the issue at all.
AnitaErnszt commentedon Jan 4, 2023
@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 🙂