Create GitHub Organization Repository instead of a user repository

TF File structure:

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

I have setup the GitHub integration in my root file like so:


terraform {
required_version = ">= 1.0.9"
backend "s3" {
required_providers {
github = {
source = "integrations/github"
version = "~> 4.0"

provider "github" {
owner = "githuborgname"
base_url = "" # we have GitHub Enterprise
token = github_mgmt_token

The github_mgmt_token is coming from an output later in the same 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 file that looks like so:

resource "github_repository" "ssc" {
name = "ssc"
description = "text"
homepage_url = ""
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?

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.