#3 added team resource and fixed crash in public key state persisting #4

Merged
lerentis merged 2 commits from feature/tt/#3-team-management into main 2022-06-25 22:38:09 +00:00
4 changed files with 69 additions and 11 deletions
Showing only changes of commit 680e2dcba2 - Show all commits

View File

@ -17,11 +17,22 @@ resource "gitea_org" "test_org" {
name = "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" { resource "gitea_team" "test_team" {
name = "Devs" name = "Devs"
organisation = gitea_org.test_org.name organisation = gitea_org.test_org.name
description = "Devs of Test Org" description = "Devs of Test Org"
permission = "write" 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 - `can_create_repos` (Boolean) Flag if the Teams members should be able to create Rpositories in the Organisation
- `description` (String) Description of the Team - `description` (String) Description of the Team
- `include_all_repositories` (Boolean) Flag if the Teams members should have access to all Repositories in the Organisation - `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 - `permission` (String) Permissions associated with this Team
Can be `none`, `read`, `write`, `admin` or `owner` 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. - `units` (String) List of types of Repositories that should be allowed to be created from Team members.

View File

@ -53,4 +53,5 @@ resource "gitea_team" "test_team" {
organisation = gitea_org.test_org.name organisation = gitea_org.test_org.name
description = "Devs of Test Org" description = "Devs of Test Org"
permission = "write" permission = "write"
members = [gitea_user.test.username]
} }

View File

@ -2,9 +2,20 @@ resource "gitea_org" "test_org" {
name = "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" { resource "gitea_team" "test_team" {
name = "Devs" name = "Devs"
organisation = gitea_org.test_org.name organisation = gitea_org.test_org.name
description = "Devs of Test Org" description = "Devs of Test Org"
permission = "write" permission = "write"
members = [gitea_user.test.username]
} }

View File

@ -17,6 +17,7 @@ const (
TeamCreateRepoFlag string = "can_create_repos" TeamCreateRepoFlag string = "can_create_repos"
TeamIncludeAllReposFlag string = "include_all_repositories" TeamIncludeAllReposFlag string = "include_all_repositories"
TeamUnits string = "units" TeamUnits string = "units"
TeamMembers string = "members"
) )
func resourceTeamRead(d *schema.ResourceData, meta interface{}) (err error) { func resourceTeamRead(d *schema.ResourceData, meta interface{}) (err error) {
@ -89,6 +90,17 @@ func resourceTeamCreate(d *schema.ResourceData, meta interface{}) (err error) {
return 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) err = setTeamResourceData(team, d)
return return
@ -158,6 +170,17 @@ func resourceTeamUpdate(d *schema.ResourceData, meta interface{}) (err error) {
return err 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) team, _, _ = client.GetTeam(id)
err = setTeamResourceData(team, d) 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(TeamIncludeAllReposFlag, team.IncludesAllRepositories)
d.Set(TeamUnits, d.Get(TeamUnits).(string)) d.Set(TeamUnits, d.Get(TeamUnits).(string))
d.Set(TeamOrg, d.Get(TeamOrg).(string)) d.Set(TeamOrg, d.Get(TeamOrg).(string))
d.Set(TeamMembers, d.Get(TeamMembers))
return 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" + 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`", "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.", Description: "`gitea_team` manages Team that are part of an organisation.",
} }