Home > Software engineering >  How to select owner while creating Github repository using terraform
How to select owner while creating Github repository using terraform

Time:07-31

I can create Github repository in an organisation as well as under my personal namespace. I'm trying to create repository under org with terraform enter image description here

But it creates the repository under my personal namespace. The token I am using is authorized to create repository under the org. How do I specify the owner/org for the repo?

Putting name as org/repoName does not seem to work.

resource "github_repository" "new-repo" {
  name        = "org/sos-repo"
  private     = true

}

CodePudding user response:

I believe the organisation is considered the owner input on the provider configuration.

This setting used to be called "organization".

You can specify it in the provider configuration block or you can use an environment variable GITHUB_OWNER.

e.g.

provider "github" {
  owner = "my-org"

  app_auth {
    id              = var.app_id              # or `GITHUB_APP_ID`
    installation_id = var.app_installation_id # or `GITHUB_APP_INSTALLATION_ID`
    pem_file        = var.app_pem_file        # or `GITHUB_APP_PEM_FILE`
  }
}

resource "github_membership" "membership_for_user_x" {
  # ...
}

resource "github_repository" "example" {
  name        = "example"
  description = "My awesome codebase"

  visibility = "public"
}
  • Related