Skip to content

Commit

Permalink
Merge pull request integrations#135 from terraform-providers/b-forcen…
Browse files Browse the repository at this point in the history
…ew-auto-init

github_repository: Make non-updatable fields ForceNew
  • Loading branch information
radeksimko authored Aug 15, 2018
2 parents 0ecf325 + 18750ea commit 0cbecbf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func resourceGithubRepository() *schema.Resource {
"auto_init": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"default_branch": {
Type: schema.TypeString,
Expand All @@ -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,
Expand Down
57 changes: 57 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
}

0 comments on commit 0cbecbf

Please sign in to comment.