Skip to content
Draft
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
4 changes: 2 additions & 2 deletions docs/resources/team.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import {
### Required

- `name` (String) Name of the team.
- `units_map` (Map of String) Map of access units. **Note**: If the `permission` is `admin` or `owner` all units must be set to `admin` as well.

### Optional

Expand All @@ -82,7 +81,8 @@ import {
- `includes_all_repositories` (Boolean) Has access to all repositories?
- `organization` (String) Name of the owning organization. Changing this forces a new resource to be created. **Note**: One of `organization` or `organization_id` must be specified.
- `organization_id` (Number) Numeric identifier of the owning organization. Changing this forces a new resource to be created. **Note**: One of `organization` or `organization_id` must be specified.
- `permission` (String) Permissions within the owning organization. **Note**: If you set `admin` or `owner` here, make sure to set the correct `units_map`.
- `permission` (String) Permissions within the owning organization. **Note**: Exactly one of `units_map` or `permission` must be defined.
- `units_map` (Map of String) Map of access units. **Note**: Exactly one of `permission` or `units_map` must be defined.

### Read-Only

Expand Down
2 changes: 0 additions & 2 deletions internal/provider/team_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ resource "forgejo_team" "test_by_id" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand All @@ -76,7 +75,6 @@ resource "forgejo_team" "test_by_name" {
organization = forgejo_organization.test.name
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand Down
3 changes: 0 additions & 3 deletions internal/provider/team_member_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand All @@ -63,7 +62,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand All @@ -90,7 +88,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand Down
5 changes: 0 additions & 5 deletions internal/provider/team_member_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand All @@ -63,7 +62,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand Down Expand Up @@ -98,7 +96,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand Down Expand Up @@ -138,7 +135,6 @@ resource "forgejo_team" "test" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand All @@ -148,7 +144,6 @@ resource "forgejo_team" "test2" {
organization_id = forgejo_organization.test.id
can_create_org_repo = true
includes_all_repositories = true
permission = "read"
units_map = {
"repo.code" = "read"
}
Expand Down
27 changes: 19 additions & 8 deletions internal/provider/team_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ func (m *teamResourceModel) to(o *forgejo.EditTeamOption, ctx context.Context) (

o.Name = m.Name.ValueString()
o.Description = m.Description.ValueStringPointer()
o.Permission = forgejo.AccessMode(m.Permission.ValueString())

if !m.Permission.IsNull() {
o.Permission = forgejo.AccessMode(m.Permission.ValueString())
}

o.CanCreateOrgRepo = m.CanCreateOrgRepo.ValueBoolPointer()
o.IncludesAllRepositories = m.IncludesAllRepositories.ValueBoolPointer()
diags = m.UnitsMap.ElementsAs(ctx, &o.UnitsMap, false)

if !m.UnitsMap.IsNull() {
diags = m.UnitsMap.ElementsAs(ctx, &o.UnitsMap, false)
}

return diags
}
Expand Down Expand Up @@ -155,24 +162,28 @@ func (r *teamResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
},
},
"permission": schema.StringAttribute{
Description: "Permissions within the owning organization. **Note**: If you set `admin` or `owner` here, make sure to set the correct `units_map`.",
Description: "Permissions within the owning organization. **Note**: Exactly one of `units_map` or `permission` must be defined.",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("read"),
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.Expressions{
path.MatchRoot("units_map"),
}...),
stringvalidator.OneOf(
"read",
"write",
"admin",
"owner",
),
},
},
"units_map": schema.MapAttribute{
Description: "Map of access units. **Note**: If the `permission` is `admin` or `owner` all units must be set to `admin` as well.",
Description: "Map of access units. **Note**: Exactly one of `permission` or `units_map` must be defined.",
ElementType: types.StringType,
Required: true,
Computed: true,
Optional: true,
Validators: []validator.Map{
mapvalidator.ExactlyOneOf(path.Expressions{
path.MatchRoot("permission"),
}...),
mapvalidator.KeysAre(
stringvalidator.OneOf(
"repo.code",
Expand Down
38 changes: 0 additions & 38 deletions internal/provider/team_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ resource "forgejo_team" "test_by_id" {
can_create_org_repo = true
description = "Test team."
includes_all_repositories = false
permission = "read"

units_map = {
"repo.issues" = "read"
Expand All @@ -67,7 +66,6 @@ resource "forgejo_team" "test_by_name" {
can_create_org_repo = true
description = "Test team."
includes_all_repositories = false
permission = "read"

units_map = {
"repo.issues" = "read"
Expand Down Expand Up @@ -116,7 +114,6 @@ resource "forgejo_team" "test_by_id" {
can_create_org_repo = true
description = "Test team."
includes_all_repositories = false
permission = "read"

units_map = {
"repo.issues" = "read"
Expand All @@ -126,7 +123,6 @@ resource "forgejo_team" "test_by_id2" {
# Make sure this second team is created later.
name = forgejo_team.test_by_id.name
organization_id = forgejo_organization.test.id
permission = "write"

units_map = {
"repo.issues" = "read"
Expand All @@ -138,7 +134,6 @@ resource "forgejo_team" "test_by_name" {
can_create_org_repo = true
description = "Test team."
includes_all_repositories = false
permission = "read"

units_map = {
"repo.issues" = "read"
Expand All @@ -148,7 +143,6 @@ resource "forgejo_team" "test_by_name2" {
# Make sure this second team is created later.
name = forgejo_team.test_by_name.name
organization = forgejo_organization.test.name
permission = "write"

units_map = {
"repo.issues" = "read"
Expand Down Expand Up @@ -204,7 +198,6 @@ resource "forgejo_team" "test_by_id" {
can_create_org_repo = false
description = "Updated test team."
includes_all_repositories = true
permission = "write"

units_map = {
"repo.issues" = "write"
Expand All @@ -216,7 +209,6 @@ resource "forgejo_team" "test_by_name" {
can_create_org_repo = false
description = "Updated test team."
includes_all_repositories = true
permission = "write"

units_map = {
"repo.issues" = "write"
Expand Down Expand Up @@ -263,7 +255,6 @@ resource "forgejo_team" "test_by_id" {
name = "renamed_test_team_by_id"
organization_id = forgejo_organization.test.id
description = "Updated test team."
permission = "write"

units_map = {
"repo.issues" = "write"
Expand All @@ -273,7 +264,6 @@ resource "forgejo_team" "test_by_name" {
name = "renamed_test_team_by_name"
organization = forgejo_organization.test.name
description = "Updated test team."
permission = "write"

units_map = {
"repo.issues" = "write"
Expand Down Expand Up @@ -322,7 +312,6 @@ resource "forgejo_organization" "new_test" {
resource "forgejo_team" "test_by_id" {
name = "renamed_test_team_by_id"
organization_id = forgejo_organization.new_test.id
permission = "write"

units_map = {
"repo.issues" = "write"
Expand All @@ -331,7 +320,6 @@ resource "forgejo_team" "test_by_id" {
resource "forgejo_team" "test_by_name" {
name = "renamed_test_team_by_name"
organization = forgejo_organization.new_test.name
permission = "write"

units_map = {
"repo.issues" = "write"
Expand Down Expand Up @@ -378,37 +366,11 @@ resource "forgejo_team" "test_by_id" {
name = "renamed_test_team_by_id"
organization_id = forgejo_organization.new_test.id
permission = "admin"

units_map = {
"repo.code" = "admin"
"repo.issues" = "admin"
"repo.pulls" = "admin"
"repo.ext_issues" = "admin"
"repo.wiki" = "admin"
"repo.ext_wiki" = "admin"
"repo.releases" = "admin"
"repo.projects" = "admin"
"repo.packages" = "admin"
"repo.actions" = "admin"
}
}
resource "forgejo_team" "test_by_name" {
name = "renamed_test_team_by_name"
organization = forgejo_organization.new_test.name
permission = "admin"

units_map = {
"repo.code" = "admin"
"repo.issues" = "admin"
"repo.pulls" = "admin"
"repo.ext_issues" = "admin"
"repo.wiki" = "admin"
"repo.ext_wiki" = "admin"
"repo.releases" = "admin"
"repo.projects" = "admin"
"repo.packages" = "admin"
"repo.actions" = "admin"
}
}`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
Expand Down
Loading