You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to create a repository in an organisation #876
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.
Reacted by Glenn Pratt, carterjones, Mario David, Alec Kloss, Bogdan Barna, Jonas Sander, A.M. Smith, Alex Angas (Dataweavers), Sorrowwill, İlkecan Bozdoğan and 1 more
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.
Reacted by Jeremy Udit, A.M. Smith, Tania Petsouka and Michael Cervantes
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 🙅🏻♂️
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?
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...
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.
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.tffile.
Should be the provider defined twice, in the root dir and submodule github_repository?
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.
@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.
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.
Activity
jeroenjacobs79 commentedon Aug 9, 2021
Update:
gh repo create headincloud/my-test-repoworks just fine, so PAT's are allowed to create organisation repositories.So, the
ownerstatement in theprovidersection 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?
nicksantamaria commentedon Aug 11, 2021
I've encountered this same problem. Using the
ownerparameter in theproviderblock did not work, but setting theGITHUB_OWNERenvvar did.glennpratt commentedon Aug 19, 2021
Seeing the same issue, which appears to be a regression from previous versions
serain commentedon Sep 17, 2021
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.
mariodavid commentedon Sep 17, 2021
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)?
remove variables for GitHub provider and use GitHub env vars
remove variables for GitHub provider and use GitHub env vars
Sinclert commentedon Oct 29, 2021
Same issue with current version (
4.17.0).It seems the documentation covering the usage of the
owner/tokenGitHub provider arguments, and how they could be replaced by theGITHUB_OWNERandGITHUB_TOKENenv. variables is misleading 🙅🏻♂️In order to get it to work:
On the provider file:
On the environment running
terraform apply:kfcampbell commentedon Nov 18, 2021
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:
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?
Sinclert commentedon Nov 18, 2021
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/githubprovider back to version4.17.0to 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
404error I got back then (regarding the creation of a branch using a non-existingmainbranch as the default source), and I thought that404error was that Terraform was not able to locate the repository in the first place...Not sure, but it seems solved.
akloss-terion commentedon Jan 31, 2022
I just encountered this with github provider 4.19.2, terraform 1.1.4.
Jonas-Sander commentedon Mar 11, 2022
This problem occured for me with 4.20.1, settings the
GITHUB_OWNERenvironment variable fixed it for me.35 remaining items
RulerOf commentedon Feb 11, 2026
It is possible to reproduce this, but it's typically always a configuration problem.
If this affects you: ensure that the
integrations/githubprovider is configured in theterraform { 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.
volker-raschek commentedon Feb 13, 2026
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.
deiga commentedon Feb 13, 2026
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
volker-raschek commentedon Feb 13, 2026
Hi @deiga,
perhaps I am not yet as familiar with Terraform as some others, but the provider
integrations/githubis defined inrequired_providersof theterraform.tffile.Should be the provider defined twice, in the root dir and submodule
github_repository?RulerOf commentedon Feb 13, 2026
Yes @volker-raschek. The example above makes it clear. You must add:
To your child module somewhere.
deiga commentedon Feb 13, 2026
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.
RulerOf commentedon Feb 13, 2026
@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.
deiga commentedon Feb 14, 2026
@RulerOf Feel free to file an Issue with them, I don't have my hopes up 😬
Update module ref to get fixed github module
import backstage repo (#488)
preciouslovethevans-dev commentedon Nov 11, 2026
deiga commentedon Nov 11, 2026
@preciouslovethevans-dev you should at least try to use more recent versions of ~everything in that toolchain