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" {

https://github.com/integrations/terraform-provider-github/blob/master/github/data_source_github_team.go#L57

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Add the github_team data source.
  2. Make sure the organization information is set in the provider
  3. Issue terraform apply

Important Factoids

References

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 29
  • Comments: 22 (5 by maintainers)

Most upvoted comments

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:

# Personal access token set by `GITHUB_TOKEN` env var
provider "github" {
  organization = "my-org"
}

data "github_team" "owner" {
  slug = "my-team"
}

This should hit the endpoint:

https://api.github.com/orgs/my-org/teams/my-team

But it is instead hitting:

https://api.github.com/orgs/my-user/teams/my-team

With my-user being the owner of the token set in the GITHUB_TOKEN env var

Can confirm the same experience. integrations/github is absolutely shattered by the above.

I was excited to move to integrations/github when I saw this message:

╷
│ Warning: Additional provider information from registry
│
│ The remote registry returned warnings for registry.terraform.io/hashicorp/github:
│ - For users on Terraform 0.13 or greater, this provider has moved to integrations/github. Please update your
│ source in required_providers.
╵

And as soon as I replaced my provider using:

terraform state replace-provider registry.terraform.io/hashicorp/github registry.terraform.io/integrations/github

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 -v shows, hashicorp/github and integrations/github are both enabled in this Terraform configuration. This means that the provider "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/github gets the correct configuration, but hashicorp/github is the plugin attempting to fetch detail of the b2b team.

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 a required_providers section specifying integrations/github, then it will implicitly refer to hashicorp/google.

All modules that you want to use integrations/github must contain

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = ">= 4.X.Y" // or whatever version range you wish
    }
  }
}

Yup, same here. It’s ignoring everything in the provider block. I was trying to pass creds in via variables.

provider "github" {
  organization = "..."
  token        = var.github_token
}

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

terraform {
  required_version = ">= 1.0.5"
  required_providers { 
    github = { // does not apply to modules
      source  = "integrations/github"
      version = "4.20.0"
    }
  }
}
provider "github" {
  app_auth {
    id              = 1234
    installation_id = 5678
    pem_file        = var.github_app_pem_file
  }
  owner = "my-org-or-acct"
}

module "secrets" { 
  source = "./modules/secrets"
}

./modules/secrets/main.tf

terraform {
  required_providers {
    github = { // explicit provider block for github is required, else hashicorp/github source is used
      source  = "integrations/github"
      version = "4.20.0"
    }
  }
}

data github_repository "some-repo" {
  name = "some-repo"
}
// then some resource that uses data.github_repository.some-repo

If the github provider is not explicitly defined in the module, tf apply will result in an error GET 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 adding GITHUB_OWNER to the environment fixed it (I was already setting GITHUB_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.

I’ve been playing around with this a little bit and I don’t think this is fundamentally broken. I’ve created the following pared-down template to reproduce this issue.

First, I’ve created a team in my org called “some-team”: some-team

Next, I’ve run the following HCL:

terraform {
  required_providers {
    github = {
      source = "integrations/github"
    }
  }
}

provider "github" {
  owner = "kfcampbell-terraform-provider"
  token = "ghp_personal_token_redacted"
}

data "github_team" "some_team" {
  slug = "some-team"
}

This is able to successfully find my team, as evidenced by the following snippet of output:

2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: ---[ REQUEST ]---------------------------------------
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: GET /orgs/kfcampbell-terraform-provider/teams/some-team HTTP/1.1
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: Host: api.github.com
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: User-Agent: go-github
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: Accept: application/vnd.github.v3+json
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: Accept-Encoding: gzip
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: -----------------------------------------------------
2021-11-18T10:47:34.447-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: 2021/11/18 10:47:34 [TRACE] Acquiring lock for GitHub API request (%!q(<nil>))
2021-11-18T10:47:34.788-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: 2021/11/18 10:47:34 [TRACE] Releasing lock for GitHub API request (%!q(<nil>))
2021-11-18T10:47:34.788-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: 2021/11/18 10:47:34 [DEBUG] Github API Response Details:
2021-11-18T10:47:34.788-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: ---[ RESPONSE ]--------------------------------------
2021-11-18T10:47:34.788-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: HTTP/2.0 200 OK
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: {
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "name": "some-team",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "id": 5373491,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "node_id": "redacted",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "slug": "some-team",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "description": "Some cool team",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "privacy": "closed",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "url": "https://api.github.com/organizations/80981761/team/5373491",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "html_url": "https://github.com/orgs/kfcampbell-terraform-provider/teams/some-team",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "members_url": "https://api.github.com/organizations/80981761/team/5373491/members{/member}",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "repositories_url": "https://api.github.com/organizations/80981761/team/5373491/repos",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "permission": "pull",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "created_at": "2021-11-15T06:19:38Z",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "updated_at": "2021-11-15T06:19:38Z",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "members_count": 0,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "repos_count": 0,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "organization": {
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "login": "kfcampbell-terraform-provider",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "id": 80981761,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "node_id": "redacted",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "url": "https://api.github.com/orgs/kfcampbell-terraform-provider",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "repos_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/repos",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "events_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/events",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "hooks_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/hooks",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "issues_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/issues",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "members_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/members{/member}",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "public_members_url": "https://api.github.com/orgs/kfcampbell-terraform-provider/public_members{/member}",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "avatar_url": "https://avatars.githubusercontent.com/u/80981761?v=4",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "description": "@kfcampbell uses this organization for testing work on the GitHub terraform provider",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "name": "kfcampbell-terraform-provider",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "company": null,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "blog": null,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "location": null,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "email": null,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "twitter_username": null,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "is_verified": false,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "has_organization_projects": true,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "has_repository_projects": true,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "public_repos": 43,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "public_gists": 0,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "followers": 0,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "following": 0,
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "html_url": "https://github.com/kfcampbell-terraform-provider",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "created_at": "2021-03-19T18:43:16Z",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "updated_at": "2021-08-18T20:25:29Z",
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:   "type": "Organization"
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  },
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0:  "parent": null
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: }
2021-11-18T10:47:34.789-0800 [DEBUG] provider.terraform-provider-github_v4.18.0: -----------------------------------------------------

I’ve also successfully done this by setting the GITHUB_OWNER and GITHUB_TOKEN environment variables instead of doing so in the provider block.

Can anybody experiencing this issue please try the above configuration and let me know if it works for you?

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_OWNER variable 👍🏼

@tibbes Many thanks for the reply. For the time being we have switched to using purely the hashicorp/github provider, which works for us.