Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not destroy the repository when you change the repository name #699

Merged
merged 5 commits into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func resourceGithubRepository() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Expand Down
62 changes: 62 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,68 @@ func TestAccGithubRepositories(t *testing.T) {

})

t.Run("updates a repositories name without error", func(t *testing.T) {

oldName := fmt.Sprintf(`tf-acc-test-rename-%[1]s`, randomID)
newName := fmt.Sprintf(`%[1]s-renamed`, oldName)

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "%[1]s"
description = "Terraform acceptance tests %[2]s"
}
`, oldName, randomID)

checks := map[string]resource.TestCheckFunc{
"before": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "name",
oldName,
),
),
"after": resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.test", "name",
newName,
),
),
}

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to add a check in here that the existing resource wasn't destroyed/a new resource wasn't created?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We manually verified that the rename operation did not cause a repository deletion by viewing audit logs for our test org:

CleanShot 2021-04-09 at 10 32 45@2x

PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: checks["before"],
},
{
// Rename the repo to something else
Config: strings.Replace(
config,
oldName,
newName, 1),
Check: checks["after"],
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
testCase(t, individual)
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})

t.Run("imports repositories without error", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down