Reputation: 81
TF File structure:
I have setup the GitHub integration in my root main.tf
file like so:
./main.tf
terraform {
required_version = ">= 1.0.9"
backend "s3" {
}
required_providers {
github = {
source = "integrations/github"
version = "~> 4.0"
}
}
}
provider "github" {
owner = "githuborgname"
base_url = "https://github.com/githuborgname/" # we have GitHub Enterprise
token = github_mgmt_token
}
The github_mgmt_token
is coming from an output later in the same main.tf
file and seems to be working well (since the repo is getting successfully created under the PAT user repos).
Inside a module I have a github-repos.tf
file that looks like so:
./moduel1/github-repos.tf
resource "github_repository" "ssc" {
name = "ssc"
description = "text"
homepage_url = "https://internalurl.com"
visibility = "private"
delete_branch_on_merge = true
auto_init = true
gitignore_template = "Python"
archive_on_destroy = true
vulnerability_alerts = true
}
This successfully creates the repo without issue but its inside the PAT user account instead of the GitHub org.
How do you create an organization repo?
Upvotes: 4
Views: 2298
Reputation: 81
I think this is a bug with 1.0.9
& 1.0.10
(at the least, maybe other versions too), if I provide the $GITHUB_OWNER
or $OWNER
env var when running the Terraform apply, this works as expected and creates the repo in the org. For some reason it does not honor/see/understand the provider arguments as expected in these versions.
Upvotes: 3
Reputation: 24271
I think you need to use the owner
argument to the provider:
owner - (Optional) This is the target GitHub organization or individual user account to manage. For example, torvalds and github are valid owners. It is optional to provide this value and it can also be sourced from the GITHUB_OWNER environment variable. When not provided and a token is available, the individual user account owning the token will be used. When not provided and no token is available, the provider may not function correctly.
taken from https://registry.terraform.io/providers/integrations/github/latest/docs
i.e.
provider "github" {
token = var.token
owner = "myorg" // <--- here
}
Upvotes: 2