New resources for managing team membership (#36)

This PR adds two new resources, _gitea_team_membership_ & _gitea_team_members_, in an attempt to decouple _gitea_team_ resources from team memberships. This facilitates the removal of members from teams without altering/recreating an existing _team_ resource.

This PR adresses this issue: https://gitea.com/gitea/terraform-provider-gitea/issues/30

The ability to set members in the _gitea_team_ resource has been removed.

The resources proposed here are inspired by similar resources in the _GitHub_ provider:
* [team_members](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_members)
* [team_membership](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_membership)

# gitea_team_members
A single resource manages all members of a team.

- This resource must be recreated when membership changes. This means, that other team members will temporarily loose their membership until the recreation of the resource is complete.
- If the recreation of the resource fails, other users will have lost their membership until the resource can be recreated.

# gitea_team_membership
A single resource holds the relationship between a single user and a single team.

-  Memberships can be deleted without affecting other users.

Reviewed-on: https://gitea.com/gitea/terraform-provider-gitea/pulls/36
Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com>
Co-authored-by: Tobias Balle-Petersen <tobiasbp@gmail.com>
Co-committed-by: Tobias Balle-Petersen <tobiasbp@gmail.com>
This commit is contained in:
Tobias Balle-Petersen
2023-11-16 00:52:16 +00:00
committed by techknowlogick
parent 0c0ab517c0
commit 557ea2673a
9 changed files with 414 additions and 35 deletions

View File

@ -69,7 +69,6 @@ resource "gitea_team" "test_team_restricted" {
- `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`
- `repositories` (List of String) List of Repositories that should be part of this team

View File

@ -0,0 +1,51 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gitea_team_members Resource - terraform-provider-gitea"
subcategory: ""
description: |-
gitea_team_members manages all members of a single team. This resource will be recreated on member changes.
---
# gitea_team_members (Resource)
`gitea_team_members` manages all members of a single team. This resource will be recreated on member changes.
## Example Usage
```terraform
resource "gitea_org" "example_org" {
name = "m_example_org"
}
resource "gitea_user" "example_users" {
count = 5
username = "m_example_user_${count.index}"
login_name = "m_example_user_${count.index}"
password = "Geheim1!"
email = "m_example_user_${count.index}@user.dev"
}
resource "gitea_team" "example_team" {
name = "m_example_team"
organisation = gitea_org.example_org.name
description = "An example of team membership"
permission = "read"
}
resource "gitea_team_members" "example_members" {
team_id = gitea_team.example_team.id
members = [for user in gitea_user.example_users : user.username]
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `members` (List of String) The user names of the members of the team.
- `team_id` (Number) The ID of the team.
### Read-Only
- `id` (String) The ID of this resource.

View File

@ -0,0 +1,52 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "gitea_team_membership Resource - terraform-provider-gitea"
subcategory: ""
description: |-
gitea_team_membership manages a single user's membership of a single team.
---
# gitea_team_membership (Resource)
`gitea_team_membership` manages a single user's membership of a single team.
## Example Usage
```terraform
resource "gitea_org" "example_org" {
name = "m_example_org"
}
resource "gitea_user" "example_users" {
count = 5
username = "m_example_user_${count.index}"
login_name = "m_example_user_${count.index}"
password = "Geheim1!"
email = "m_example_user_${count.index}@user.dev"
}
resource "gitea_team" "example_team" {
name = "m_example_team"
organisation = gitea_org.example_org.name
description = "An example team for membership testing"
permission = "read"
}
resource "gitea_team_membership" "example_team_memberships" {
for_each = { for user in gitea_user.example_users : user.username => user }
team_id = gitea_team.example_team.id
username = each.value["username"]
}
```
<!-- schema generated by tfplugindocs -->
## Schema
### Required
- `team_id` (Number) The ID of the team.
- `username` (String) The username of the team member.
### Read-Only
- `id` (String) The ID of this resource.