From ec1d73297e326021cdd3c1f7ac5e1fb16cb50cc7 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Sun, 5 Jan 2020 14:11:26 -0800 Subject: [PATCH] Fix issues with auto_init destroying repositories From github API perspective setting or modifying `auto_init` only makes sense in the context of creating a new repository. Changing it after is ignored by the github API which is the behavior we should (and use to) match. The only scenario where this makes sense to assume that changing this intends on a destructive action (blowing up a github repo is not something that should be easy accidentally) is when you use the `terraform taint` command but for very different reasons. This change is related to several PRs that subverts the communities expectations with no real or perceived value. Signed-off-by: Ben Abrams --- github/resource_github_repository.go | 2 +- github/resource_github_repository_test.go | 67 ----------------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 3d13d6e97f..92970e4cf2 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -77,7 +77,7 @@ func resourceGithubRepository() *schema.Resource { "auto_init": { Type: schema.TypeBool, Optional: true, - ForceNew: true, + ForceNew: false, }, "default_branch": { Type: schema.TypeString, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index b18e8926cd..4c72c5f9c7 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -448,48 +448,6 @@ func TestAccGithubRepository_topics(t *testing.T) { }) } -func TestAccGithubRepository_autoInitForceNew(t *testing.T) { - var repo github.Repository - - rn := "github_repository.foo" - randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) - name := fmt.Sprintf("tf-acc-test-%s", randString) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckGithubRepositoryDestroy, - Steps: []resource.TestStep{ - { - Config: testAccGithubRepositoryConfigAutoInitForceNew(randString), - Check: resource.ComposeTestCheckFunc( - testAccCheckGithubRepositoryExists(rn, &repo), - resource.TestCheckResourceAttr(rn, "name", name), - resource.TestCheckResourceAttr(rn, "auto_init", "false"), - ), - }, - { - Config: testAccGithubRepositoryConfigAutoInitForceNewUpdate(randString), - Check: resource.ComposeTestCheckFunc( - testAccCheckGithubRepositoryExists(rn, &repo), - resource.TestCheckResourceAttr(rn, "name", name), - resource.TestCheckResourceAttr(rn, "auto_init", "true"), - resource.TestCheckResourceAttr(rn, "license_template", "mpl-2.0"), - resource.TestCheckResourceAttr(rn, "gitignore_template", "Go"), - ), - }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "auto_init", "license_template", "gitignore_template", - }, - }, - }, - }) -} - func testAccCheckGithubRepositoryExists(n string, repo *github.Repository) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -856,28 +814,3 @@ 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) -}