Skip to content

Unable to create a repository in an organisation #876

Closed

Description

@jeroenjacobs79

Hello,

I'm trying to create a repository in an organisation using my personal access token. My config is something like this:


terraform {
  required_version = "=1.0.3"
  required_providers {
    aws = {
      version = "=3.52.0"
      source = "hashicorp/aws"
    }
    tls = {
      source = "hashicorp/tls"
      version = "=3.1.0"
    }
    github = {
      source  = "integrations/github"
      version = "=4.13.0"
    }
  }
}
provider "github" {
  owner = "headincloud"
}

resource "github_repository" "app_repo" {
  name        = "cluster-apps"
  description = "App repository"

  visibility = "private"
  delete_branch_on_merge = "true"
}

I have set the GITHUB_TOKEN to my PAT (which I granted all the permissions for now), but the repo still gets created under my own user-name, not onder my organisation.

Now, maybe creating organisation repos doesn't work with PAT's, and I should use OAuth? But I have no clue on how to proceed with this. When trying to create a new GitHub OAuth app, it asks for a homepage URL and callback URL but I have no clue on what I should put here for TerraForm. The documentation is not clear on this either...

So, what is the correct approach here? I believe the documentation could be improved on this subject.

Terraform version: 1.0.3
Github provider version: 4.13.0

Activity

  1. jeroenjacobs79 commented on Aug 9, 2021

    @jeroenjacobs79
    Author

    Update:

    gh repo create headincloud/my-test-repo works just fine, so PAT's are allowed to create organisation repositories.

    So, the owner statement in the provider section seems to get ignored? I have no other GITHUB_* env set, only GITHUB_TOKEN.

    Update 2:

    So it works when I set GITHUB_OWNER. Am I correct to assume that if you use GITHUB_TOKEN env var, you also need to use the GITHUB_OWNER env var?

  2. nicksantamaria commented on Aug 11, 2021

    @nicksantamaria

    I've encountered this same problem. Using the owner parameter in the provider block did not work, but setting the GITHUB_OWNER envvar did.

  3. glennpratt commented on Aug 19, 2021

    @glennpratt

    Seeing the same issue, which appears to be a regression from previous versions

  4. added
    Type: Bug
    on Aug 31, 2021
  5. serain commented on Sep 17, 2021

    @serain

    I faced this issue only when trying to create a repo in a child module. It doesn't pick up the org configuration from the parent module and you have to explicitly pass an aliased provider to the module.

  6. mariodavid commented on Sep 17, 2021

    @mariodavid

    hi @serain ,

    I'm facing the same issue within the module. Can you show an example of how you passed in the provider to the module? Just via a dedicated variable in the module or via the provider meta argument from the module (https://www.terraform.io/docs/language/meta-arguments/module-providers.html)?

  7. Sinclert commented on Oct 29, 2021

    @Sinclert

    Same issue with current version (4.17.0).

    It seems the documentation covering the usage of the owner / token GitHub provider arguments, and how they could be replaced by the GITHUB_OWNER and GITHUB_TOKEN env. variables is misleading 🙅🏻‍♂️

    In order to get it to work:

    • On the provider file:

      provider "github" {}
    • On the environment running terraform apply:

      export GITHUB_OWNER="your-org-name-here"
      export GITHUB_TOKEN="your-secret-token-here"
      
  8. kfcampbell commented on Nov 18, 2021

    @kfcampbell
    Contributor

    I've spent some time playing with this recently, and I'm not able to reproduce the issue. Here's a super pared-down template as an example:

    terraform {
      required_providers {
        github = {
          source = "integrations/github"
          version = "4.18.0"
        }
      }
    }
    
    provider "github" {
      owner = "kfcampbell-terraform-provider"
      token = "ghp_personal_token_redacted"
    }
    
    
    resource "github_repository" "app_repo" {
      name        = "876-repro"
      description = "App repository"
    
      visibility = "private"
      delete_branch_on_merge = "true"
    }
    

    That repo has been created successfully here in my test organization rather than my personal profile. Can you try that reproduction and let me know if it works for you?

  9. Sinclert commented on Nov 18, 2021

    @Sinclert

    Hi @kfcampbell , thanks for your reply 👋🏻

    I just ran your example, changing the owner between my personal account, and an owned organization account, getting it to work in both. Then I tried switching my integrations/github provider back to version 4.17.0 to try to replicate my original setup. However, I could not get the same results as I got when I wrote in this issue 🤔

    Perhaps I was confused with another 404 error I got back then (regarding the creation of a branch using a non-existing main branch as the default source), and I thought that 404 error was that Terraform was not able to locate the repository in the first place...

    Not sure, but it seems solved.

  10. akloss-terion commented on Jan 31, 2022

    @akloss-terion

    I just encountered this with github provider 4.19.2, terraform 1.1.4.

  11. Jonas-Sander commented on Mar 11, 2022

    @Jonas-Sander

    This problem occured for me with 4.20.1, settings the GITHUB_OWNER environment variable fixed it for me.

  12. 35 remaining items

  13. moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Activeon Feb 11, 2026
  14. RulerOf commented on Feb 11, 2026

    @RulerOf
    Contributor

    It is possible to reproduce this, but it's typically always a configuration problem.

    If this affects you: ensure that the integrations/github provider is configured in the terraform { required_providers {} } block in your root module and in every submodule down to where your resources are defined.

    For a concrete example, see my comment further up the thread.


    @deiga I humbly suggest locking this discussion to ensure this comment remains visible into the future.

  15. volker-raschek commented on Feb 13, 2026

    @volker-raschek

    Hi @deiga,
    I've create a GitHub repository to reproduce the issue: https://github.com/volker-raschek/terraform-github-provider-issue

    Please go through the README file to reproduce it.

  16. deiga commented on Feb 13, 2026

    @deiga
    Collaborator

    Hi @deiga,
    I've create a GitHub repository to reproduce the issue: https://github.com/volker-raschek/terraform-github-provider-issue

    Please go through the README file to reproduce it.

    Thanks for that! Amazing!

    Without running it, I can see that the module doesn't have the required_providers config, which is my main guess at the issue.

    This is not something we can fix AFAIK, as long as hashicorp/github provider exists

  17. volker-raschek commented on Feb 13, 2026

    @volker-raschek

    Hi @deiga,
    perhaps I am not yet as familiar with Terraform as some others, but the provider integrations/github is defined in required_providers of the terraform.tf file.

    Should be the provider defined twice, in the root dir and submodule github_repository?

  18. RulerOf commented on Feb 13, 2026

    @RulerOf
    Contributor

    Should be the provider defined twice, in the root dir and submodule github_repository?

    Yes @volker-raschek. The example above makes it clear. You must add:

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

    To your child module somewhere.

  19. deiga commented on Feb 13, 2026

    @deiga
    Collaborator

    You need to consider that a module is a semi-autonomous part, which knows only what's given into it or defined inside it. Maybe like a Class in OOP.
    And this extends to dependencies in a limited fashion, but due to the naming confusion of the legacy hashicorp/github provider (and auto-resolution of Hashicorp providers) it creates this silly situation.

  20. RulerOf commented on Feb 13, 2026

    @RulerOf
    Contributor

    @deiga it does stand to reason that a patch to core terraform is called for by this issue. Although I've got no idea what their appetite would be to change this kind of default.

  21. deiga commented on Feb 14, 2026

    @deiga
    Collaborator

    @RulerOf Feel free to file an Issue with them, I don't have my hopes up 😬

  22. preciouslovethevans-dev commented on Nov 11, 2026

    @preciouslovethevans-dev

    Hello,

    I'm trying to create a repository in an organisation using my personal access token. My config is something like this:

    
    
    
    terraform {
    
      required_version = "=1.0.3"
    
      required_providers {
    
        aws = {
    
          version = "=3.52.0"
    
          source = "hashicorp/aws"
    
        }
    
        tls = {
    
          source = "hashicorp/tls"
    
          version = "=3.1.0"
    
        }
    
        github = {
    
          source  = "integrations/github"
    
          version = "=4.13.0"
    
        }
    
      }
    
    }
    
    provider "github" {
    
      owner = "headincloud"
    
    }
    
    
    
    resource "github_repository" "app_repo" {
    
      name        = "cluster-apps"
    
      description = "App repository"
    
    
    
      visibility = "private"
    
      delete_branch_on_merge = "true"
    
    }
    
    
    
    

    I have set the GITHUB_TOKEN to my PAT (which I granted all the permissions for now), but the repo still gets created under my own user-name, not onder my organisation.

    Now, maybe creating organisation repos doesn't work with PAT's, and I should use OAuth? But I have no clue on how to proceed with this. When trying to create a new GitHub OAuth app, it asks for a homepage URL and callback URL but I have no clue on what I should put here for TerraForm. The documentation is not clear on this either...

    So, what is the correct approach here? I believe the documentation could be improved on this subject.

    Terraform version: 1.0.3

    Github provider version: 4.13.0

  23. deiga commented on Nov 11, 2026

    @deiga
    Collaborator

    @preciouslovethevans-dev you should at least try to use more recent versions of ~everything in that toolchain

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthenticationProviderStatus: PinnedStatus: Up for grabsType: Bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions