Skip to content

Support personal repositories not only GitHub organization #45

Closed

Description

@jugatsu

Terraform Version

v0.9.5

Affected Resource(s)

  • github_repository

Terraform Configuration Files

provider "github" {
  token        = "${var.github_token}"
}

resource "github_repository" "otus-devops-terraform" {
  name        = "otus-devops-terraform"
  description = "Repository for public terraform code using in Otus DevOps course"
}

resource "github_repository" "practice-git-1" {
  name        = "practice-git-1"
  description = "Repository for practicing Git in Otus DevOps course"
}

resource "github_repository" "practice-git-2" {
  name        = "practice-git-2"
  has_issues  = true
  description = "Repository for practicing Git in Otus DevOps course"
}

Debug Output

terraform.tfstate

{
    "version": 3,
    "terraform_version": "0.9.5",
    "serial": 2,
    "lineage": "753781c3-ade7-4b8d-9723-2f7f9bbdb08b",
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {},
            "depends_on": []
        }
    ]
}

Expected Behavior

It should create repository under personal account and write state in terraform.tfstate

Actual Behavior

terraform asks Github oraganization when running with terraform apply. Also it returns 422 when running twice. So it isn't idempotent.

Steps to Reproduce

terraform apply

Activity

  1. added
    Type: Feature
    on Aug 31, 2017
  2. changed the title [-][FEATURE REQUEST] Support personal repositories not only GitHub organization[/-] [+]Support personal repositories not only GitHub organization[/+] on Aug 31, 2017
  3. TraGicCode commented on Sep 18, 2017

    @TraGicCode

    Any updates on this?

  4. paultyng commented on Mar 13, 2018

    @paultyng
    Contributor

    Related to #77

  5. frostebite commented on Jan 14, 2019

    @frostebite

    Any update on this? It would be great!

  6. kquinsland01 commented on Jan 19, 2019

    @kquinsland01

    the username is the github_orginization if you're operating under the personal/free account (it appears that in the GET Repos URL, the org argument sent to the provider is set as the owner in the request)

    I was able to get tf import github_repo... to work with a personal access token.
    I was able to run tf apply after importing and got a correct/successful "no changes needed"
    I then tried to change the name of the repo in terraform, and am now getting:
    github_repository.test: POST https://api.github.com/orgs/kquinsland/repos: 404 Not Found []

    Looking at the API Docs there is a different URL endpoint for creating in an org (POST /orgs/:org/repos) versus creating for a user (POST /user/repos. I'm very new to golang, is there a significant amount of work involved to add a simple account_type value to the provider, where a value of user informs the provider to use the user version of the necessary APIs and a value of org uses the APIs that are currently there?

  7. phillip-bailey commented on Mar 2, 2019

    @phillip-bailey

    Having the possibilty to create and manage personal repositories from TF would be amazing, especially for demos. Any updates down the line?

  8. phillip-bailey commented on Mar 24, 2019

    @phillip-bailey

    Hello there,
    Meanwhile waiting for a fix into GitHub Terraform provider. I have just released a Terraform module for anyone interested to set GitHup personal repositories. It's a bit raw, though.

    https://github.com/p0bailey/terraform-github-personal-repositories

  9. binlab commented on Jan 20, 2020

    @binlab

    Any updates on this?

  10. phillip-bailey commented on Jan 23, 2020

    @phillip-bailey

    Any updates on this?

    Everything seems blocked.

  11. ahaffar commented on Mar 9, 2020

    @ahaffar

    i am using github_provider version 2.4.1 and it works for individual repos

    provider "github" {
      version = "> 2.4"
      token = var.token
      individual = false
      organization = var.organization
    }
    

    where organization is the username

  12. mrtazz commented on Mar 25, 2020

    @mrtazz

    this worked for me. With version 2.4.1 configured for my individual account as above I was at least able to:

    • import state
    • add a collaborator to a repo
    • mark a repo as archived
  13. cornfeedhobo commented on Mar 29, 2020

    @cornfeedhobo
    Contributor

    I am unable to confirm @mrtazz's success:

    Provider

    provider "github" {
        version    = "~> 2.4"
        individual = true
    }
    $ terraform init
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "github" (hashicorp/github) 2.4.1...
    ...snip...
    

    Applying

    resource "github_repository" "test" {
        name = "terraform-github_branch-test"
    }
    $ terraform apply
    ...snip...
    github_repository.test: Creating...
    
    Error: This resource requires GitHub organization to be set on the provider.
    
      on main.tf line 5, in resource "github_repository" "test":
       5: resource "github_repository" "test" {
    

    Importing

    resource "github_repository" "test" {
        name = "go-travis-testing"
    }
    $ terraform import github_repository.test cornfeedhobo:go-travis-testing
    github_repository.test: Importing from ID "cornfeedhobo:go-travis-testing"...
    github_repository.test: Import prepared!
      Prepared github_repository for import
    github_repository.test: Refreshing state... [id=cornfeedhobo:terraform-github_branch-test]
    
    Error: This resource requires GitHub organization to be set on the provider.
    

    Fixing this should close #50, #56, and #96.

    @shoekstra @jcudit pinging you because I stumbled into this while attempting to test importing with github_branch.

  14. mrtazz commented on Mar 30, 2020

    @mrtazz

    @cornfeedhobo you need to set individual = false in the provider config. That's kinda the weird thing here. The provider then treats your individual account as an org, so there will definitely be edge cases that don't work.

  15. 12 remaining items

  16. janaka commented on Apr 17, 2020

    @janaka

    Pretty sure perms are good. I'll need to double check as it's been some days.

  17. janaka commented on Apr 18, 2020

    @janaka

    FYI - I moved the repo from my personal to an Org (the personal account owns) and all is now working. Same token with no perms changes. Provider 2.6.1.

  18. clebio commented on Aug 12, 2020

    @clebio

    Sorry, what is the fix here for the github_repository data source? Nothing I see described above seems to work. I'm on provider.github v2.9.2 and getting

    Error: GET https://api.github.com/orgs/clebio: 404 Not Found []

  19. cornfeedhobo commented on Aug 12, 2020

    @cornfeedhobo
    Contributor

    @clebio pretty sure this was reverted

  20. janaka commented on Aug 13, 2020

    @janaka

    Given orgs became free around the same time, I just created one and moved my repo there.

  21. josjaf commented on Aug 23, 2020

    @josjaf

    I'm now having the issue - @cornfeedhobo - how do you know it was reverted? I cannot easily create an organization because I'm part of a few already.

  22. cornfeedhobo commented on Aug 24, 2020

    @cornfeedhobo
    Contributor
  23. josjaf commented on Sep 1, 2020

    @josjaf

    Any idea what the workaround is for personal repositories for now?

  24. cornfeedhobo commented on Sep 2, 2020

    @cornfeedhobo
    Contributor

    @josjaf there is none that I know of right now. Sounds like most people have created orgs for the meantime.

  25. abitrolly commented on Sep 3, 2020

    @abitrolly

    @josjaf I moved to GitLab.

  26. ggsood commented on Dec 25, 2020

    @ggsood

    This issue is now resolved now as per the provider version v4.1.0, you can create a github repo in your personal profile as

    provider "github" {
      owner = "<GITHUB_USERNAME>"
      token = "<GITHUB_TOKEN>"
    }
    
    resource "github_repository" "terraformed" {
      name        = "terraformed"
      description = "A repository created by Terraform"
      visibility  = "private"
    } 
    

    Thanks Community for fixing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: Feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions