From 8977f87f60c707d073af45d5ec5485469a2af991 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Sun, 26 Jun 2022 00:18:20 +0200 Subject: [PATCH] #3 teams can not have members --- docs/resources/team.md | 18 ++++++++++-- examples/main.tf | 9 +++--- examples/resources/gitea_team/resource.tf | 19 ++++++++++--- gitea/resource_gitea_team.go | 34 +++++++++++++++++++++++ 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/docs/resources/team.md b/docs/resources/team.md index a16f48b..6434ca7 100644 --- a/docs/resources/team.md +++ b/docs/resources/team.md @@ -17,11 +17,22 @@ resource "gitea_org" "test_org" { name = "test-org" } +resource "gitea_user" "test" { + username = "test" + login_name = "test" + password = "Geheim1!" + email = "test@user.dev" + must_change_password = false + admin = true +} + + resource "gitea_team" "test_team" { - name = "Devs" + name = "Devs" organisation = gitea_org.test_org.name - description = "Devs of Test Org" - permission = "write" + description = "Devs of Test Org" + permission = "write" + members = [gitea_user.test.username] } ``` @@ -38,6 +49,7 @@ resource "gitea_team" "test_team" { - `can_create_repos` (Boolean) Flag if the Teams members should be able to create Rpositories in the Organisation - `description` (String) Description of the Team - `include_all_repositories` (Boolean) Flag if the Teams members should have access to all Repositories in the Organisation +- `members` (List of String) List of Users that should be part of this team - `permission` (String) Permissions associated with this Team Can be `none`, `read`, `write`, `admin` or `owner` - `units` (String) List of types of Repositories that should be allowed to be created from Team members. diff --git a/examples/main.tf b/examples/main.tf index ff9a3d5..79b3707 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -49,8 +49,9 @@ resource "gitea_public_key" "test_user_key" { resource "gitea_team" "test_team" { - name = "Devs" + name = "Devs" organisation = gitea_org.test_org.name - description = "Devs of Test Org" - permission = "write" -} \ No newline at end of file + description = "Devs of Test Org" + permission = "write" + members = [gitea_user.test.username] +} diff --git a/examples/resources/gitea_team/resource.tf b/examples/resources/gitea_team/resource.tf index 08ce5d5..7accce0 100644 --- a/examples/resources/gitea_team/resource.tf +++ b/examples/resources/gitea_team/resource.tf @@ -2,9 +2,20 @@ resource "gitea_org" "test_org" { name = "test-org" } +resource "gitea_user" "test" { + username = "test" + login_name = "test" + password = "Geheim1!" + email = "test@user.dev" + must_change_password = false + admin = true +} + + resource "gitea_team" "test_team" { - name = "Devs" + name = "Devs" organisation = gitea_org.test_org.name - description = "Devs of Test Org" - permission = "write" -} \ No newline at end of file + description = "Devs of Test Org" + permission = "write" + members = [gitea_user.test.username] +} diff --git a/gitea/resource_gitea_team.go b/gitea/resource_gitea_team.go index 2d98115..8bfed82 100644 --- a/gitea/resource_gitea_team.go +++ b/gitea/resource_gitea_team.go @@ -17,6 +17,7 @@ const ( TeamCreateRepoFlag string = "can_create_repos" TeamIncludeAllReposFlag string = "include_all_repositories" TeamUnits string = "units" + TeamMembers string = "members" ) func resourceTeamRead(d *schema.ResourceData, meta interface{}) (err error) { @@ -89,6 +90,17 @@ func resourceTeamCreate(d *schema.ResourceData, meta interface{}) (err error) { return } + users := d.Get(TeamMembers).([]interface{}) + + for _, user := range users { + if user != "" { + _, err = client.AddTeamMember(team.ID, user.(string)) + if err != nil { + return err + } + } + } + err = setTeamResourceData(team, d) return @@ -158,6 +170,17 @@ func resourceTeamUpdate(d *schema.ResourceData, meta interface{}) (err error) { return err } + users := d.Get(TeamMembers).([]interface{}) + + for _, user := range users { + if user != "" { + _, err = client.AddTeamMember(team.ID, user.(string)) + if err != nil { + return err + } + } + } + team, _, _ = client.GetTeam(id) err = setTeamResourceData(team, d) @@ -194,6 +217,7 @@ func setTeamResourceData(team *gitea.Team, d *schema.ResourceData) (err error) { d.Set(TeamIncludeAllReposFlag, team.IncludesAllRepositories) d.Set(TeamUnits, d.Get(TeamUnits).(string)) d.Set(TeamOrg, d.Get(TeamOrg).(string)) + d.Set(TeamMembers, d.Get(TeamMembers)) return } @@ -256,6 +280,16 @@ func resourceGiteaTeam() *schema.Resource { Description: "List of types of Repositories that should be allowed to be created from Team members.\n" + "Can be `repo.code`, `repo.issues`, `repo.ext_issues`, `repo.wiki`, `repo.pulls`, `repo.releases`, `repo.projects` and/or `repo.ext_wiki`", }, + "members": { + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + Required: false, + Computed: true, + Description: "List of Users that should be part of this team", + }, }, Description: "`gitea_team` manages Team that are part of an organisation.", }