diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 88614b1d17..c3798bfd77 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -244,10 +244,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er // Can only set `default_branch` on an already created repository with the target branches ref already in-place if v, ok := d.GetOk("default_branch"); ok { branch := v.(string) - // If branch is "master", and the repository hasn't been initialized yet, setting this value will fail - if branch != "master" { - repoReq.DefaultBranch = &branch - } + repoReq.DefaultBranch = &branch } repoName := d.Id() diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 327a3787cd..34dbea7716 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -262,6 +262,26 @@ func TestAccGithubRepository_defaultBranch(t *testing.T) { }), ), }, + { + Config: testAccGithubRepositoryUpdateConfigMasterDefaultBranch(randString), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryExists("github_repository.foo", &repo), + testAccCheckGithubRepositoryAttributes(&repo, &testAccGithubRepositoryExpectedAttributes{ + Name: name, + Description: "Updated " + description, + Homepage: "http://example.com/", + AutoInit: true, + HasIssues: true, + HasWiki: true, + AllowMergeCommit: true, + AllowSquashMerge: false, + AllowRebaseMerge: false, + HasDownloads: true, + DefaultBranch: "master", + Archived: false, + }), + ), + }, }, }) } @@ -718,6 +738,29 @@ resource "github_repository" "foo" { `, randString, randString) } +func testAccGithubRepositoryUpdateConfigMasterDefaultBranch(randString string) string { + return fmt.Sprintf(` +resource "github_repository" "foo" { + name = "tf-acc-test-%s" + description = "Updated Terraform acceptance tests %s" + homepage_url = "http://example.com/" + + # So that acceptance tests can be run in a github organization + # with no billing + private = false + + has_issues = true + has_wiki = true + allow_merge_commit = true + allow_squash_merge = false + allow_rebase_merge = false + has_downloads = true + auto_init = true + default_branch = "master" +} +`, randString, randString) +} + func testAccGithubRepositoryConfigTemplates(randString string) string { return fmt.Sprintf(` resource "github_repository" "foo" {