Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data source github_team returns 404 #655

Closed
eleni-salamani opened this issue Jan 12, 2021 · 24 comments
Closed

Data source github_team returns 404 #655

eleni-salamani opened this issue Jan 12, 2021 · 24 comments
Assignees
Labels
Authentication d/team Provider Status: Stale Used by stalebot to clean house Type: Bug Something isn't working as documented

Comments

@eleni-salamani
Copy link

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

@erumble
Copy link

erumble commented Jan 12, 2021

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

@jcudit jcudit added Type: Bug Something isn't working as documented d/team labels Jan 14, 2021
@jspiro
Copy link
Contributor

jspiro commented Jan 20, 2021

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.

@jspiro
Copy link
Contributor

jspiro commented Jan 20, 2021

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.

@jspiro
Copy link
Contributor

jspiro commented Jan 20, 2021

It's a regression since 2.9. I can't say when – I'm only finally able to upgrade now that github_branch_protection_v3 exists.

@aliculPix4D
Copy link

Same here. After using the workaround by @jspiro and using environment vars for both everything works fine.

@wmborelli
Copy link

wmborelli commented Feb 9, 2021

FYI I'm hitting a similar issue using resource "github_team" -
Error: DELETE https://{internal_api_url}/orgs/{org}/teams/{team}/memberships/{owner}: 404 Not Found []
It looks like it creates the team with myself as the maintainer and then attempts to delete me before adding the ldap_dn attribute (I'm assuming). Setting create_default_maintainer = false doesn't solve anything.

I'll try to open another issue on this when I have more time.

@tibbes
Copy link
Contributor

tibbes commented Mar 22, 2021

@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
    }
  }
}

@eleni-salamani
Copy link
Author

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

@jcudit jcudit removed this from the v4.9.0 milestone Apr 17, 2021
@sidcarter
Copy link

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.

@jbcom
Copy link

jbcom commented Jul 4, 2021

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

@renuka-sharma
Copy link

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.
I do not have the hashicorp provider specified anywhere in the code but it still attempts to use it and keeps failing

@andreswebs
Copy link

I confirm having the same problem as above, and switching to hashicorp/github fixes it

@PaulusTM
Copy link

For me it worked to set the org name as GITHUB_OWNER variable 👍🏼

@jbcom
Copy link

jbcom commented Nov 1, 2021

Doesn't work here as of the latest. Still the same problem using GITHUB_OWNER

@kfcampbell
Copy link
Member

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?

@gnarea
Copy link

gnarea commented Dec 9, 2021

@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.

@kfcampbell kfcampbell mentioned this issue Dec 21, 2021
3 tasks
@jbcom
Copy link

jbcom commented Jan 31, 2022

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.

@robtayl0r
Copy link

robtayl0r commented Feb 8, 2022

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 [].

@apujari-hippo
Copy link

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 [].

The above solution will not work as my data is in data.tf and providers are in main.tf. If I explicitly add a provider to data.tf I get the following error:

A module may have only one required providers configuration. The required providers were previously configured at main.tf:2,3-21.

@apujari-hippo
Copy link

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 [].

The above solution will not work as my data is in data.tf and providers are in main.tf. If I explicitly add a provider to data.tf I get the following error:

A module may have only one required providers configuration. The required providers were previously configured at main.tf:2,3-21.

Moved all code to main.tf. Still facing the issue. I encounter this issue when using app_auth for authentication(token works fine).

provider "github" {
  app_auth {
    id              = var.app_id              # or `GITHUB_APP_ID`
    installation_id = var.app_installation_id # or `GITHUB_APP_INSTALLATION_ID`
    pem_file        = var.app_pem_file        # or `GITHUB_APP_PEM_FILE`
  }
}

@ermirizio
Copy link

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 [].

Hi, I'm using terraform cloud as remote backend and I can said none of the above solutions works for me, when using either local backend or s3 bucket it works just fine. Any hints/discoveries on this?

@nickfloyd nickfloyd moved this to 🆕 Triage in 🧰 Octokit Active Jan 4, 2023
@nickfloyd nickfloyd self-assigned this Jan 4, 2023
@nickfloyd nickfloyd moved this from 🆕 Triage to 🔖 Ready in 🧰 Octokit Active Jan 4, 2023
@nickfloyd nickfloyd moved this from 🔖 Ready to 🏗 In progress in 🧰 Octokit Active Jan 4, 2023
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Oct 2, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2023
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Oct 10, 2023
@h3nryza
Copy link

h3nryza commented Jun 5, 2024

I have a similar issue where I am trying to use the resource github_actions_environment_secret.
The API returns a 404 with a repos// which should only be one /
I have defined Owner/Repo and using a PAT with full access as a test and still get the error.
Went on to define ../owner/repo which corrected the URL but still gives me a 404

Used the API directly to confirm the PAT and payload were correct and because I define the URL is worked 100%.

Seeing similar issues
#1805
pulumi/pulumi-github#248

@vveliev-tc
Copy link

@nickfloyd any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Authentication d/team Provider Status: Stale Used by stalebot to clean house Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests