Skip to content

Commit c968888

Browse files
PabloPiekfcampbell
andauthored
feat: allow team slug instead of team id in github_team and github_team_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 <[email protected]>
1 parent a5bb4a4 commit c968888

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

github/resource_github_team.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ func resourceGithubTeam() *schema.Resource {
4747
ValidateFunc: validateValueFunc([]string{"secret", "closed"}),
4848
},
4949
"parent_team_id": {
50-
Type: schema.TypeInt,
50+
Type: schema.TypeString,
5151
Optional: true,
52-
Description: "The ID of the parent team, if this is a nested team.",
52+
Description: "The ID or slug of the parent team, if this is a nested team.",
5353
},
5454
"ldap_dn": {
5555
Type: schema.TypeString,
@@ -106,8 +106,11 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
106106
}
107107

108108
if parentTeamID, ok := d.GetOk("parent_team_id"); ok {
109-
id := int64(parentTeamID.(int))
110-
newTeam.ParentTeamID = &id
109+
teamId, err := getTeamID(parentTeamID.(string), meta)
110+
if err != nil {
111+
return err
112+
}
113+
newTeam.ParentTeamID = &teamId
111114
}
112115
ctx := context.Background()
113116

github/resource_github_team_members.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ func resourceGithubTeamMembers() *schema.Resource {
2626

2727
Schema: map[string]*schema.Schema{
2828
"team_id": {
29-
Type: schema.TypeString,
30-
Required: true,
31-
ForceNew: true,
32-
Description: "The GitHub team id.",
33-
ValidateFunc: validateTeamIDFunc,
29+
Type: schema.TypeString,
30+
Required: true,
31+
ForceNew: true,
32+
Description: "The GitHub team id or slug",
3433
},
3534
"members": {
3635
Type: schema.TypeSet,

github/resource_github_team_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,25 @@ func TestAccGithubTeamHierarchical(t *testing.T) {
6565
description = "Terraform acc test parent team"
6666
privacy = "closed"
6767
}
68-
68+
6969
resource "github_team" "child" {
7070
name = "tf-acc-child-%[1]s"
7171
description = "Terraform acc test child team"
7272
privacy = "closed"
7373
parent_team_id = "${github_team.parent.id}"
7474
}
75+
76+
resource "github_team" "child2" {
77+
name = "tf-acc-child-2-%[1]s"
78+
description = "Terraform acc test child 2 team"
79+
privacy = "closed"
80+
parent_team_id = "${github_team.parent.slug}"
81+
}
7582
`, randomID)
7683

7784
check := resource.ComposeTestCheckFunc(
7885
resource.TestCheckResourceAttrSet("github_team.child", "parent_team_id"),
86+
resource.TestCheckResourceAttrSet("github_team.child2", "parent_team_id"),
7987
)
8088

8189
testCase := func(t *testing.T, mode string) {

website/docs/r/team.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The following arguments are supported:
3131
* `description` - (Optional) A description of the team.
3232
* `privacy` - (Optional) The level of privacy for the team. Must be one of `secret` or `closed`.
3333
Defaults to `secret`.
34-
* `parent_team_id` - (Optional) The ID of the parent team, if this is a nested team.
34+
* `parent_team_id` - (Optional) The ID or slug of the parent team, if this is a nested team.
3535
* `ldap_dn` - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only available in GitHub Enterprise Server.
3636
* `create_default_maintainer` - (Optional) Adds a default maintainer to the team. Defaults to `false` and adds the creating user to the team when `true`.
3737

0 commit comments

Comments
 (0)