Allow managing members in the project resource (#480)

* Extend resource and datasource

* Adapt acc test to work without members

* Extend acc test and adjust resource

* Generate docs

* Fix lint

* Fix unit test

* Uniformize description with datasource and extend unit test

* Improve role field description

* Update TF state before adding/removing members

* Remove unused function

* Move intermediate map top state to mapProjectFields

* Improve code
This commit is contained in:
João Palet 2024-07-29 09:57:06 +01:00 committed by GitHub
parent af7d789945
commit 31ce9ab36d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1195 additions and 169 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/teambition/rrule-go"
)
@ -137,6 +138,23 @@ func NoSeparator() *Validator {
}
}
func NonLegacyProjectRole() *Validator {
description := "legacy roles are not supported"
return &Validator{
description: description,
validate: func(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
if utils.IsLegacyProjectRole(req.ConfigValue.ValueString()) {
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
req.Path,
description,
req.ConfigValue.ValueString(),
))
}
},
}
}
func MinorVersionNumber() *Validator {
description := "value must be a minor version number, without a leading 'v': '[MAJOR].[MINOR]'"

View file

@ -299,6 +299,60 @@ func TestNoSeparator(t *testing.T) {
}
}
func TestNonLegacyProjectRole(t *testing.T) {
tests := []struct {
description string
input string
isValid bool
}{
{
"ok",
"owner",
true,
},
{
"ok-2",
"reader",
true,
},
{
"leagcy-role",
"project.owner",
false,
},
{
"leagcy-role-2",
"project.admin",
false,
},
{
"leagcy-role-3",
"project.member",
false,
},
{
"leagcy-role-4",
"project.auditor",
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
r := validator.StringResponse{}
NonLegacyProjectRole().ValidateString(context.Background(), validator.StringRequest{
ConfigValue: types.StringValue(tt.input),
}, &r)
if !tt.isValid && !r.Diagnostics.HasError() {
t.Fatalf("Should have failed")
}
if tt.isValid && r.Diagnostics.HasError() {
t.Fatalf("Should not have failed: %v", r.Diagnostics.Errors())
}
})
}
}
func TestMinorVersionNumber(t *testing.T) {
tests := []struct {
description string