Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Setting the github_repository.default_branch on creation to any designated value #513

Closed
sheldonhull opened this issue Jul 14, 2020 · 4 comments
Milestone

Comments

@sheldonhull
Copy link

Affected Resource(s)

Please list the resources as a list, for example:

  • github_repository.default_branch

Expected Behavior

In support of the more modern naming convention that GitHub is adopting for allowing the default branch to be main by default rather than master, I attempted to update my git repo management project to use the same convention.

I expected the default_branch attribute of github_repository to allow setting this.

Actual Behavior

The provider returned an error:

Error: Cannot set the default branch on a new repository to something other than 'master'.

  on main.tf line 5, in resource "github_repository" "repo":
   5: resource "github_repository" "repo" {

Limits

If this is a provider limitation with GitHub right now, and not able to be resolved immediately, I'd suggest this be marked as a pinned item to revisit in a few months after GitHub finishes these changes. This is part of the better inclusive language that GitHub is working to support and if the current provider is limited, would be good to pin to have as item to support once GitHub fixes it.

@particledecay
Copy link

I'll add my support for this. This restriction effectively means that this isn't actually a declarative representation of a GitHub repository.

Imagine you're trying to migrate from GitHub to GitHub Enterprise, let's say. How do you define the repositories declaratively? You can't. Instead, you might be inclined to use something like Ansible to do this, since you are forced to reason about this in an imperative fashion anyway.

If you can't specify the default_branch value you want because the repo doesn't exist, you also might be inclined to perform a hack like not specifying default_branch in the github_repository resource, and specifying a github_branch resource afterwards to create your branch, and then adding default_branch in another github_repository. The problem is that the first resource will always detect a change because it's assuming the default branch is master, and it's not.

I think the best approach so that this can behave in a declarative fashion is to create the branch if it doesn't exist. Obviously this would only work with auto_init = true, since you can't create a branch on an empty repo.

If someone's more familiar than I am with this provider code, have at it. Otherwise, I can take a look and see if I can figure it out.

@jcudit
Copy link
Contributor

jcudit commented Oct 4, 2020

☝️ has shipped which aligns our testing to the new state of repositories that are created.

The planned next step here is to add logic to create the branch requested by default_branch if it does not exist. On creation, we will then update the default branch configuration to use the newly requested branch. In the end, the user will only need to declare the name of the default_branch and the provider will abstract management of branches.

@ColinHarrington
Copy link

ColinHarrington commented Oct 19, 2020

I would like to use the default main branch, but the rest of our tooling needs to come along for the ride. We'll need a good migration path forward.

Creating a new Repository:

When creating a new Repository, I'd like to be able to specify a default_branch other than main
I'd also like for github_branch_protection to be utilize this default_branch in one apply

For example:

resource "github_repository" "test" {
    name           = "repo-with-default-branch-develop"
    description    = "Repository with a default branch other than main"
    default_branch = "develop"					
    auto_init = true    
}

resource "github_branch_protection" "example" {
  repository     = github_repository.test.name
  branch         = "develop"  
}

Updating the default_branch on existing repositories

I'd like the ability to change the default_branch of an existing repository to main

  1. Existing Repository
resource "github_repository" "test" {
    name           = "repo"
    description    = "..."
    default_branch = "develop"					
    auto_init = true    
}
  1. Update the default_branch to main
resource "github_repository" "test" {
   name           = "repo"
   description    = "..."
   default_branch = "main"					
   auto_init = true    
}

I'd expect that the default_branch in Github and Terraform state to be main

@jcudit jcudit modified the milestones: v4.1.0, v4.1.1 Nov 22, 2020
@jcudit
Copy link
Contributor

jcudit commented Nov 26, 2020

I think this is now resolved with the merge of https://github.com/terraform-providers/terraform-provider-github/pull/194. Please re-open if there is more to do here.

@jcudit jcudit closed this as completed Nov 26, 2020
@jcudit jcudit modified the milestones: v4.1.1, v4.1.0 Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants