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

feat: allow team slug instead of team id in github_team and github_team_members #1664

Merged
merged 5 commits into from
May 1, 2023
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
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