Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform: create GitHub Organization Repository instead of a user repository

TF File structure:

  • ./
    • main.tf (see code below, github provider defined here)
    • module1 (folder)
      • module1.tfvars
      • github-repos.tf (see code below)
      • main.tf (blank)
      • variables.tf (defined for the module, value comes from tfvar file)
    • module2 (folder)
    • module3 (folder)

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?

like image 335
Matthew Avatar asked Nov 01 '25 00:11

Matthew


1 Answers

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.

like image 130
Matthew Avatar answered Nov 04 '25 19:11

Matthew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!