Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
AuthenticationStatus: StaleUsed by stalebot to clean houseType: BugSomething isn't working as documented
Description
Terraform Version
terraform -v
Terraform v1.0.4
on darwin_amd64
Affected Resource(s)
Please list the resources as a list, for example:
- github_team
Terraform Configuration Files
terraform {
required_providers {
github = {
source = "hashicorp/github"
version = "= 2.9.0"
}
}
}
# Exported GITHUB_TOKEN, GITHUB_OWNER, and GITHUB_ORGANIZATION to shell
provider "github" {}
resource "github_team" "some_team" {
name = "some-team"
description = "Some cool team"
privacy = "closed"
}Debug Output
Debug in gist:
https://gist.github.com/KyMidd/12336386b5a65db6fac73c1f6bab29f6
Expected Behavior
Terraform should use PAT to make changes to enterprise org.
Actual Behavior
Terraform provider reports either empty user, user name same as org name (?), PAT user's username, and reports "Error: This resource can only be used in the context of an organization, "KyMidd" is a user."
Terraform will perform the following actions:
# github_team.some_team will be created
+ resource "github_team" "some_team" {
+ create_default_maintainer = false
+ description = "Some cool team"
+ etag = (known after apply)
+ id = (known after apply)
+ members_count = (known after apply)
+ name = "some-team"
+ node_id = (known after apply)
+ privacy = "closed"
+ slug = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
github_team.some_team: Creating...
╷
│ Error: This resource can only be used in the context of an organization, "KyMidd" is a user.
│
│ with github_team.some_team,
│ on main.tf line 17, in resource "github_team" "some_team":
│ 17: resource "github_team" "some_team" {
│ Steps to Reproduce
- Create above config
- Exported GITHUB_TOKEN, GITHUB_OWNER, and GITHUB_ORGANIZATION to shell
- terraform init
- terraform apply
Important Factoids
- Normal GitHub org within enterprise. PAT has full admin access to Org.
- Have tested 2.9.0 provider, as well as newest version (4.13.0) of github/terraform-provider-github as well as integrations/terraform-provider-github
- I've read about the bugs this provider has around reading env variables vs provider static info, Org vs Owner, and have tried lots of combinations. None has worked so far.
References
Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:
Reacted by carterjones, Jean-Yves CAMIER, Kyler Middleton, Alexander Myasnikov, Carl Molinari, Alexander Dove, Alex Harden, Sai Gunaranjan, Ben Harrison, Tanvir Sidhu and 4 more
Metadata
Metadata
Assignees
Labels
AuthenticationStatus: StaleUsed by stalebot to clean houseType: BugSomething isn't working as documented
Activity
KyMidd commentedon Aug 11, 2021
Okay, through attempting about 100 things, found a combination that lets this work:
Given those 4 things line up, this provider works to create and manage resources.
KyMidd commentedon Aug 12, 2021
Now I'm building the provider locally from "integrations/terraform-provider-github" and it's failing to authenticate. Is the integration/ copy of this provider just flat broken auth-wise right now?
GITHUB_TOKEN is populated with a valid token.
Init pulls in both the local provider that I've specified as well as the hashicorp/ version of the provider (rather than integrations/), likely due to me calling a module? Appears to be an open issue in another issue.
And here's the error message, same as saw earlier.
nicksantamaria commentedon Aug 25, 2021
Might be related to #876
Looks like the fix over there is to set the
GITHUB_OWNERenv var.KyMidd commentedon Aug 25, 2021
Same behavior after exporting
GITHUB_OWNERinto shell:I have written a GraphQL add-on to manage team auto-assignment, and I'd love for the provider to natively support it, but unable to develop in this state. Any ideas welcome.
KyMidd commentedon Sep 3, 2021
Saw v4.14.0 that PR #867 shipped and informs about authentication. I refreshed my copy of code, built local, and see the same issues.
Two interesting things:
Unfortunately, auth still appears entirely broken. Any suggestions or testing you'd like to see I'm happy to do :) Thanks all!
kyler
[-]Create Team in Org within Enterprise Failing: "resource can only be used in the context of an organization"[/-][+]integration/terraform-provider-github auth doesn't work: "resource can only be used in the context of an organization"[/+]KyMidd commentedon Sep 24, 2021
Hey team, after the recent releases I attempted this again. I built the provider:
I exported the GITHUB_TOKEN in my terminal
My github provider block specifies the org:
And it worked 💥 💥 .
Whatever ya'll have done to fix auth in the past few PRs, it appears to have worked. Since I can now compile and get a working copy, I can hopefully start developing and add some feature. Thanks all! I'll close this issue.
KyMidd commentedon Sep 24, 2021
Okay, weird. This works great on my local computer, but in GitHub Actions running on Ubuntu 20.04 container, it doesn't. Is there any difference between the Mac version of this provider and Ubuntu linux 20.04 version? Didn't test this, b/c I didn't expect it. I'll reopen this issue, as it still appears broken on some platforms.
On Ubuntu 20.04, working:
Not working:
Provider block for both, and both export GITHUB_TOKEN into the shell as a variable.
Any thoughts?
jcudit commentedon Oct 5, 2021
Thanks for the reports! We're collecting information on how to best fix our authentication issues. Adding the
authenticationlabel to track and hope to bring a fix to our next major release.ahmadnassri commentedon Oct 11, 2021
I can confirm this is still the issue on
4.16.0and4.15.1...integrations/githubbrokenhashicorp/githubworks finekfcampbell commentedon Nov 18, 2021
I've been playing around with this a little further and I don't believe this behavior is fundamentally broken. Here's a super-pared-down repro case that makes this evident:
I've exported my GITHUB_TOKEN and GITHUB_OWNER environment variables as such:
although it works the same if these variables are provided in the
providerblock of the above configuration as well.The team is successfully created in my organization:
Can you please try the above reproduction and let me know if it works for you?
KyMidd commentedon Dec 10, 2021
Hey @kfcampbell : I no longer have access to this environment to test, but @asgr86 or @JordanKochVeradigm might be able to test this out, tagging in case they can.
Based on your testing, it doesn't appear a mixed configuration vs environmental variables config is supported, and must fully use one or the other. And also the organization vs owners is sometimes broken and documentation isn't clear why.
Thank you for taking this on, huge pain trying to scale our github horizontally without proper tooling that works reliably. Best of luck sorting this out!
alexdepalex commentedon Feb 9, 2022
Still seems to be broken on GH Enterprise 3.2.7 and integrations/github 4.20.0.
paul-civitas commentedon Mar 21, 2022
This was working for me before but I updated my provider and now it's broken :(
bluehawk27 commentedon Apr 4, 2022
@kfcampbell thank you for that comment. Your suggested course of action worked for me on 4.23.0
paul-civitas commentedon Apr 4, 2022
In my case the issue turned out to be an expired github token.
Not the error message I expected from an expired token.
dmitry-mightydevops commentedon Nov 19, 2022
on my side that error
belongs to the use of
github_team_repositoryresourceso I had to
github_team_repositoryresourcesmy provider is latest 5.9.0, terraform 1.3.4
All resources are authenticated just fine, except for the team permissions.
I have selected the following Permissions for the github app:
Repository permissions
Organization permissions
Seems that should be a sufficient for github_team_repository, but it still fails.
Interesting thing is that the association (i.e. team_repository) is created successfully, but then still fails with the error message,
As reported here: #1373
github-actions commentedon Aug 17, 2023
👋 Hey Friends, this issue has been automatically marked as
stalebecause it has no recent activity. It will be closed if no further activity occurs. Please add theStatus: Pinnedlabel if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!KyMidd commentedon Aug 24, 2023
I think closed is fine, Keegan is aggregating reports to the super-issue here: #980
Thanks to Keegan and all folks who are supporting this software! We appreciate you <3