Skip to content

Commit

Permalink
Fix issues with auto_init destroying repositories
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
majormoses committed Jan 5, 2020
1 parent 2c03b95 commit d9fa07e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 59 deletions.
2 changes: 1 addition & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func resourceGithubRepository() *schema.Resource {
"auto_init": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
ForceNew: false,
},
"default_branch": {
Type: schema.TypeString,
Expand Down
58 changes: 0 additions & 58 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -865,19 +823,3 @@ resource "github_repository" "foo" {
}
`, 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)
}

0 comments on commit d9fa07e

Please sign in to comment.