Skip to content

Commit

Permalink
team: mark slug as computed when name changes (integrations#757)
Browse files Browse the repository at this point in the history
* team: mark slug as computed when name changes

* add test

* vendor
  • Loading branch information
bendrucker authored May 7, 2021
1 parent 50a27bb commit e8d3ab3
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 0 deletions.
7 changes: 7 additions & 0 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/google/go-github/v32/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/shurcooL/githubv4"
)
Expand All @@ -21,6 +22,12 @@ func resourceGithubTeam() *schema.Resource {
State: schema.ImportStatePassthrough,
},

CustomizeDiff: customdiff.Sequence(
customdiff.ComputedIf("slug", func(d *schema.ResourceDiff, meta interface{}) bool {
return d.HasChange("name")
}),
),

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down
58 changes: 58 additions & 0 deletions github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,61 @@ func TestAccGithubTeamRemovesDefaultMaintainer(t *testing.T) {
})

}

func TestAccGithubTeamUpdateName(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

t.Run("marks the slug as computed when the name changes", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_team" "test" {
name = "tf-acc-%s"
}
`, randomID)

configUpdated := fmt.Sprintf(`
resource "github_team" "test" {
name = "tf-acc-updated-%s"
}
resource "github_team" "other" {
name = "tf-acc-other-%s"
description = github_team.test.slug
}
`, randomID, randomID)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team.test", "slug", fmt.Sprintf("tf-acc-%s", randomID)),
),
},
{
Config: configUpdated,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("github_team.other", "description", fmt.Sprintf("tf-acc-updated-%s", randomID)),
),
},
},
})
}

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) {
t.Skip("individual account not supported for this operation")
})

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

})
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ github.com/hashicorp/terraform-json
## explicit
github.com/hashicorp/terraform-plugin-sdk/acctest
github.com/hashicorp/terraform-plugin-sdk/helper/acctest
github.com/hashicorp/terraform-plugin-sdk/helper/customdiff
github.com/hashicorp/terraform-plugin-sdk/helper/hashcode
github.com/hashicorp/terraform-plugin-sdk/helper/logging
github.com/hashicorp/terraform-plugin-sdk/helper/resource
Expand Down

0 comments on commit e8d3ab3

Please sign in to comment.