#3 teams can not have members
Some checks reported errors
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build was killed

This commit is contained in:
Tobias Trabelsi 2022-06-26 00:18:20 +02:00
parent 6e63797167
commit 8977f87f60
Signed by: lerentis
GPG Key ID: FF0C2839718CAF2E
4 changed files with 69 additions and 11 deletions

View File

@ -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.

View File

@ -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"
}
description = "Devs of Test Org"
permission = "write"
members = [gitea_user.test.username]
}

View File

@ -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"
}
description = "Devs of Test Org"
permission = "write"
members = [gitea_user.test.username]
}

View File

@ -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.",
}