terraform-provider-github: Data source github_team returns 404
Using the github_team data source with the latest provider version returns 404.
Terraform Version
✗ terraform -v Terraform v0.13.6
- provider registry.terraform.io/hashicorp/aws v2.48.0
- provider registry.terraform.io/hashicorp/github v4.1.0
- provider registry.terraform.io/hashicorp/null v2.1.2
- provider registry.terraform.io/integrations/github v4.2.0
Affected Resource(s)
- github_team data source
Terraform Configuration Files
data "github_team" "team_details" {
for_each = var.teams
slug = each.key
}
resource "github_team_repository" "repository_team" {
for_each = var.teams
repository = github_repository.repository.name
team_id = data.github_team.team_details[each.key].id
permission = each.value
}
and the provider configuration
terraform {
required_providers {
github = {
source = "integrations/github"
version = "4.2.0"
}
}
}
provider "github" {
version = "4.2.0"
organization = "myorg"
token = "blabla"
}
Debug Output
https://gist.github.com/eleni-salamani/bf0a8d0173700c95e6451ff6c78600a7
Panic Output
Expected Behavior
The data source should return the team information so that it can be used in further resources.
Actual Behavior
The call returns 404. It seems the API call is not built correctly as the organization is not set.
Error: GET https://api.github.com/orgs//teams/b2b: 404 Not Found []
on modules/repository/main.tf line 61, in data "github_team" "team_details":
61: data "github_team" "team_details" {
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
- Add the github_team data source.
- Make sure the organization information is set in the provider
- Issue
terraform apply
Important Factoids
References
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 29
- Comments: 22 (5 by maintainers)
I’m experiencing the same issue. It looks like the org information is not being pulled from the provider’s configuration, but from the token. My config looks like:
This should hit the endpoint:
But it is instead hitting:
With
my-userbeing the owner of the token set in theGITHUB_TOKENenv varCan confirm the same experience. integrations/github is absolutely shattered by the above.
I was excited to move to
integrations/githubwhen I saw this message:And as soon as I replaced my provider using:
all github stuff broke. Tried a few things, but didn’t fix it.
So, just removing the source in required_providers fixed the problem for me. Serves me right to be jumping to the new stuff immediately.
@eleni-salamani, @jspiro, @aliculPix4D, I believe that this is the same issue as #696 and #697.
As the output of
terraform -vshows,hashicorp/githubandintegrations/githubare both enabled in this Terraform configuration. This means that theprovider "github"block is sent to one of the providers but not the other, which means that the other provider is working in anonymous mode with no token, no owner, and no organization.According to the debug output in the gist @eleni-salamani, it looks like
integrations/githubgets the correct configuration, buthashicorp/githubis the plugin attempting to fetch detail of theb2bteam.If you genuinely need to use both providers, then you need to configure both providers using local names. However, it’s also possible that your Terraform configuration is accidentally referring to
hashicorp/google: if you use any module that attempts to use the GitHub provider, but does not declare arequired_providerssection specifyingintegrations/github, then it will implicitly refer tohashicorp/google.All modules that you want to use
integrations/githubmust containYup, same here. It’s ignoring everything in the provider block. I was trying to pass creds in via variables.
It always returns
Error: This resource can only be used in the context of an organization, "" is a user.Or I get rate limited because it’s not authenticating.
Workaround: Use environment vars for both.
It seems within a module, if a “github” required_providers block is not defined, the (deprecated?) “hashicorp/github” provider is used.
For example, in order to resolve terraform’s 404 errors to the github api, I needed to:
./main.tf./modules/secrets/main.tfIf the github provider is not explicitly defined in the module,
tf applywill result in an errorGET https://api.github.com/repos//some-repo: 404 Not Found [].@kfcampbell, I experienced all the symptoms described here but with a different resource (
github_branch_protection_v3), and addingGITHUB_OWNERto the environment fixed it (I was already settingGITHUB_TOKEN).Unfortunately, in my case, this meant I had to do a major refactoring because I was using two separate GitHub providers to manager repos in two different organisations, so I had to break up the workspace into two (one for each org) – even though I really would’ve preferred to keep everything in one workspace.
This is much broader than the data source, the provider is not inferring the organization from the provider in any circumstance for me. You may want to rename your bug.
Still doesn’t work for me unfortunately.
Doesn’t work here as of the latest. Still the same problem using GITHUB_OWNER
For me it worked to set the org name as
GITHUB_OWNERvariable 👍🏼@tibbes Many thanks for the reply. For the time being we have switched to using purely the
hashicorp/githubprovider, which works for us.