Skip to content

Commit

Permalink
feat: allow team slug instead of team id in github_team and github_te…
Browse files Browse the repository at this point in the history
…am_members (#1664)

* fix: remove validation for team_id as it can also be a string

* feat: allow team slug for parent team id in team resource

* docs: add slug option to team resource

* feat: add test for gihub_team using slug for parent_team_id

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
PabloPie and kfcampbell authored May 1, 2023
1 parent a5bb4a4 commit c968888
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
11 changes: 7 additions & 4 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func resourceGithubTeam() *schema.Resource {
ValidateFunc: validateValueFunc([]string{"secret", "closed"}),
},
"parent_team_id": {
Type: schema.TypeInt,
Type: schema.TypeString,
Optional: true,
Description: "The ID of the parent team, if this is a nested team.",
Description: "The ID or slug of the parent team, if this is a nested team.",
},
"ldap_dn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -106,8 +106,11 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
}

if parentTeamID, ok := d.GetOk("parent_team_id"); ok {
id := int64(parentTeamID.(int))
newTeam.ParentTeamID = &id
teamId, err := getTeamID(parentTeamID.(string), meta)
if err != nil {
return err
}
newTeam.ParentTeamID = &teamId
}
ctx := context.Background()

Expand Down
9 changes: 4 additions & 5 deletions github/resource_github_team_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ func resourceGithubTeamMembers() *schema.Resource {

Schema: map[string]*schema.Schema{
"team_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The GitHub team id.",
ValidateFunc: validateTeamIDFunc,
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The GitHub team id or slug",
},
"members": {
Type: schema.TypeSet,
Expand Down
10 changes: 9 additions & 1 deletion github/resource_github_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,25 @@ func TestAccGithubTeamHierarchical(t *testing.T) {
description = "Terraform acc test parent team"
privacy = "closed"
}
resource "github_team" "child" {
name = "tf-acc-child-%[1]s"
description = "Terraform acc test child team"
privacy = "closed"
parent_team_id = "${github_team.parent.id}"
}
resource "github_team" "child2" {
name = "tf-acc-child-2-%[1]s"
description = "Terraform acc test child 2 team"
privacy = "closed"
parent_team_id = "${github_team.parent.slug}"
}
`, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("github_team.child", "parent_team_id"),
resource.TestCheckResourceAttrSet("github_team.child2", "parent_team_id"),
)

testCase := func(t *testing.T, mode string) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/team.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The following arguments are supported:
* `description` - (Optional) A description of the team.
* `privacy` - (Optional) The level of privacy for the team. Must be one of `secret` or `closed`.
Defaults to `secret`.
* `parent_team_id` - (Optional) The ID of the parent team, if this is a nested team.
* `parent_team_id` - (Optional) The ID or slug of the parent team, if this is a nested team.
* `ldap_dn` - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise Server.
* `create_default_maintainer` - (Optional) Adds a default maintainer to the team. Defaults to `false` and adds the creating user to the team when `true`.

Expand Down

0 comments on commit c968888

Please sign in to comment.