Skip to content

Data source github_team returns 404 #655

Closed as not planned
Closed as not planned

Description

@eleni-salamani

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

Activity

  1. erumble commented on Jan 12, 2021

    @erumble

    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

  2. added
    Type: Bug
    on Jan 14, 2021
  3. jspiro commented on Jan 20, 2021

    @jspiro
    Contributor

    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.

  4. jspiro commented on Jan 20, 2021

    @jspiro
    Contributor

    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.

  5. jspiro commented on Jan 20, 2021

    @jspiro
    Contributor

    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.

  6. aliculPix4D commented on Jan 20, 2021

    @aliculPix4D

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

  7. added this to the v4.6.0 milestone on Feb 8, 2021
  8. wmborelli commented on Feb 9, 2021

    @wmborelli

    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.

  9. tibbes commented on Mar 22, 2021

    @tibbes
    Contributor

    @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
        }
      }
    }
    
  10. eleni-salamani commented on Mar 22, 2021

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

  11. removed this from the v4.9.0 milestone on Apr 17, 2021
  12. sidcarter commented on Jun 28, 2021

    @sidcarter

    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.

  13. jbdevprimary commented on Jul 4, 2021

    @jbdevprimary

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

  14. 8 remaining items

  15. robtayl0r commented on Feb 8, 2022

    @robtayl0r

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

  16. apujari-hippo commented on Oct 21, 2022

    @apujari-hippo

    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.
    
  17. apujari-hippo commented on Oct 21, 2022

    @apujari-hippo

    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`
      }
    }
    
  18. ermirizio commented on Oct 26, 2022

    @ermirizio

    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?

  19. moved this to 🆕 Triage in 🧰 Octokit Activeon Jan 4, 2023
  20. self-assigned this
    on Jan 4, 2023
  21. moved this from 🆕 Triage to 🔖 Ready in 🧰 Octokit Activeon Jan 4, 2023
  22. moved this from 🔖 Ready to 🏗 In progress in 🧰 Octokit Activeon Jan 4, 2023
  23. github-actions commented on Oct 2, 2023

    @github-actions

    👋 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!

  24. added
    Status: Stale
    on Oct 2, 2023
  25. moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Activeon Oct 10, 2023
  26. h3nryza commented on Jun 5, 2024

    @h3nryza

    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

  27. vveliev-tc commented on Jul 15, 2024

    @vveliev-tc

    @nickfloyd any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AuthenticationProviderStatus: StaleType: Bugd/team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions