diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9929ae1bc3..688180c256 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -72,6 +72,7 @@ func resourceGithubRepository() *schema.Resource { "auto_init": { Type: schema.TypeBool, Optional: true, + ForceNew: true, }, "default_branch": { Type: schema.TypeString, @@ -82,10 +83,12 @@ func resourceGithubRepository() *schema.Resource { "license_template": { Type: schema.TypeString, Optional: true, + ForceNew: true, }, "gitignore_template": { Type: schema.TypeString, Optional: true, + ForceNew: true, }, "archived": { Type: schema.TypeBool, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index abdb117675..cf9f521379 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -371,6 +371,38 @@ func TestAccGithubRepository_topics(t *testing.T) { }) } +func TestAccGithubRepository_autoInitForceNew(t *testing.T) { + var repo github.Repository + randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) + name := fmt.Sprintf("tf-acc-test-%s", randString) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckGithubRepositoryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGithubRepositoryConfigAutoInitForceNew(randString), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryExists("github_repository.foo", &repo), + resource.TestCheckResourceAttr("github_repository.foo", "name", name), + resource.TestCheckResourceAttr("github_repository.foo", "auto_init", "false"), + ), + }, + { + Config: testAccGithubRepositoryConfigAutoInitForceNewUpdate(randString), + Check: resource.ComposeTestCheckFunc( + testAccCheckGithubRepositoryExists("github_repository.foo", &repo), + resource.TestCheckResourceAttr("github_repository.foo", "name", name), + resource.TestCheckResourceAttr("github_repository.foo", "auto_init", "true"), + resource.TestCheckResourceAttr("github_repository.foo", "license_template", "mpl-2.0"), + resource.TestCheckResourceAttr("github_repository.foo", "gitignore_template", "Go"), + ), + }, + }, + }) +} + func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -721,3 +753,28 @@ resource "github_repository" "foo" { } `, randString, randString, topicList) } + +func testAccGithubRepositoryConfigAutoInitForceNew(randString string) string { + return fmt.Sprintf(` +resource "github_repository" "foo" { + name = "tf-acc-test-%s" + auto_init = false +} +`, randString) +} + +func testAccGithubRepositoryConfigAutoInitForceNewUpdate(randString string) string { + return fmt.Sprintf(` +resource "github_repository" "foo" { + name = "tf-acc-test-%s" + auto_init = true + license_template = "mpl-2.0" + gitignore_template = "Go" +} + +resource "github_branch_protection" "repo_name_master" { + repository = "${github_repository.foo.name}" + branch = "master" +} +`, randString) +}