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

@ -6,6 +6,7 @@ import (
"strings"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/hashicorp/terraform-plugin-framework/types"
)
@ -14,6 +15,10 @@ const (
SKEServiceId = "cloud.stackit.ske"
)
var (
LegacyProjectRoles = []string{"project.admin", "project.auditor", "project.member", "project.owner"}
)
// ReconcileStringSlices reconciles two string lists by removing elements from the
// first list that are not in the second list and appending elements from the
// second list that are not in the first list.
@ -85,13 +90,17 @@ func SupportedValuesDocumentation(values []string) string {
if len(values) == 0 {
return ""
}
return "Supported values are: " + strings.Join(quoteValues(values), ", ") + "."
return "Supported values are: " + strings.Join(QuoteValues(values), ", ") + "."
}
func quoteValues(values []string) []string {
func QuoteValues(values []string) []string {
quotedValues := make([]string, len(values))
for i, value := range values {
quotedValues[i] = fmt.Sprintf("`%s`", value)
}
return quotedValues
}
func IsLegacyProjectRole(role string) bool {
return utils.Contains(LegacyProjectRoles, role)
}

View file

@ -225,3 +225,46 @@ func TestSupportedValuesDocumentation(t *testing.T) {
})
}
}
func TestIsLegacyProjectRole(t *testing.T) {
tests := []struct {
description string
role string
expected bool
}{
{
"non legacy role",
"owner",
false,
},
{
"leagcy role",
"project.owner",
true,
},
{
"leagcy role 2",
"project.admin",
true,
},
{
"leagcy role 3",
"project.member",
true,
},
{
"leagcy role 4",
"project.auditor",
true,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output := IsLegacyProjectRole(tt.role)
if output != tt.expected {
t.Fatalf("Data does not match: %v", output)
}
})
}
}