Skip to content

Commit

Permalink
feat(domain): add validators for role and workspace assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszPorowski committed Mar 7, 2025
1 parent f718768 commit d585a5a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 4 additions & 0 deletions internal/services/domain/resource_domain_role_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -108,6 +109,9 @@ func (r *resourceDomainRoleAssignments) Schema(ctx context.Context, _ resource.S
},
},
},
Validators: []validator.Object{
objectvalidator.IsRequired(),
},
},
},
"timeouts": timeouts.AttributesAll(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"slices"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
fabadmin "github.com/microsoft/fabric-sdk-go/fabric/admin"
Expand Down Expand Up @@ -78,6 +80,9 @@ func (r *resourceDomainWorkspaceAssignments) Schema(ctx context.Context, _ resou
MarkdownDescription: "The set of Workspace IDs.",
Required: true,
ElementType: customtypes.UUIDType{},
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
},
},
"timeouts": timeouts.AttributesAll(ctx),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ func TestAcc_DomainWorkspaceAssignmentsResource_CRUD(t *testing.T) {

domainResourceFQN := testhelp.ResourceFQN("fabric", itemTFName, "test")

entity := testhelp.WellKnown()["WorkspaceRS"].(map[string]any)
entityID := entity["id"].(string)
entity1 := testhelp.WellKnown()["WorkspaceRS"].(map[string]any)
entity1ID := entity1["id"].(string)

entity2 := testhelp.WellKnown()["WorkspaceDS"].(map[string]any)
entity2ID := entity2["id"].(string)

resource.Test(t, testhelp.NewTestAccCase(t, nil, nil, []resource.TestStep{
// Create and Read
Expand All @@ -98,14 +101,34 @@ func TestAcc_DomainWorkspaceAssignmentsResource_CRUD(t *testing.T) {
map[string]any{
"domain_id": testhelp.RefByFQN(domainResourceFQN, "id"),
"workspace_ids": []string{
entityID,
entity1ID,
},
},
),
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.#", "1"),
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.0", entityID),
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.0", entity1ID),
),
},
// Update and Read
{
ResourceName: testResourceDomainWorkspaceAssignments,
Config: at.JoinConfigs(
domainResourceHCL,
at.CompileConfig(
testResourceDomainWorkspaceAssignmentsHeader,
map[string]any{
"domain_id": testhelp.RefByFQN(domainResourceFQN, "id"),
"workspace_ids": []string{
entity1ID,
entity2ID,
},
},
),
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.#", "2"),
),
},
// Update and Read
Expand All @@ -116,13 +139,16 @@ func TestAcc_DomainWorkspaceAssignmentsResource_CRUD(t *testing.T) {
at.CompileConfig(
testResourceDomainWorkspaceAssignmentsHeader,
map[string]any{
"domain_id": testhelp.RefByFQN(domainResourceFQN, "id"),
"workspace_ids": []string{},
"domain_id": testhelp.RefByFQN(domainResourceFQN, "id"),
"workspace_ids": []string{
entity2ID,
},
},
),
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.#", "0"),
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.#", "1"),
resource.TestCheckResourceAttr(testResourceDomainWorkspaceAssignments, "workspace_ids.0", entity2ID),
),
},
}))
Expand Down

0 comments on commit d585a5a

Please sign in to comment.