Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(domain): workspace assignments should only care about managed resources #182

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changes/unreleased/fixed-20250108-115142.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: fixed
body: |
`Provider produced inconsistent result after apply` error appears when using `fabric_domain_workspace_assignments` multiple times due to enforce assignments based only on TF configuration and ignoring the real state on the Fabric side.
Resource must only manage TF provided configuration and ignore any configuration provided outside TF.
time: 2025-01-08T11:51:42.1488752-08:00
custom:
Issue: "174"
2 changes: 1 addition & 1 deletion docs/resources/domain_workspace_assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resource "fabric_domain_workspace_assignments" "example" {
### Required

- `domain_id` (String) The Domain ID. Changing this forces a new resource to be created.
- `workspace_ids` (Set of String) The list of Workspaces.
- `workspace_ids` (Set of String) The set of Workspace IDs.

### Optional

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type resourceDomainWorkspaceAssignmentsModel struct {
Timeouts timeouts.Value `tfsdk:"timeouts"`
}

func (to *resourceDomainWorkspaceAssignmentsModel) setWorkspaces(ctx context.Context, from []fabadmin.DomainWorkspace) diag.Diagnostics {
elements := []customtypes.UUID{}
func (to *resourceDomainWorkspaceAssignmentsModel) setWorkspaces(ctx context.Context, from []string) diag.Diagnostics {
elements := make([]customtypes.UUID, 0, len(from))

for _, entity := range from {
elements = append(elements, customtypes.NewUUIDPointerValue(entity.ID))
for _, element := range from {
elements = append(elements, customtypes.NewUUIDValue(element))
}

values, diags := types.SetValueFrom(ctx, customtypes.UUIDType{}, elements)
Expand Down Expand Up @@ -69,15 +69,14 @@ func (to *requestDeleteDomainWorkspaceAssignments) set(ctx context.Context, from
}

func getWorkspaceIDs(ctx context.Context, from resourceDomainWorkspaceAssignmentsModel) ([]string, diag.Diagnostics) {
values := []string{}

elements := make([]customtypes.UUID, 0, len(from.WorkspaceIDs.Elements()))

diags := from.WorkspaceIDs.ElementsAs(ctx, &elements, false)
if diags.HasError() {
if diags := from.WorkspaceIDs.ElementsAs(ctx, &elements, false); diags.HasError() {
return nil, diags
}

values := make([]string, 0, len(elements))

for _, element := range elements {
values = append(values, element.ValueString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package domain
import (
"context"
"fmt"
"slices"

"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (r *resourceDomainWorkspaceAssignments) Schema(ctx context.Context, _ resou
},
},
"workspace_ids": schema.SetAttribute{
MarkdownDescription: "The list of Workspaces.",
MarkdownDescription: "The set of Workspace IDs.",
Required: true,
ElementType: customtypes.UUIDType{},
},
Expand Down Expand Up @@ -309,15 +310,13 @@ func (r *resourceDomainWorkspaceAssignments) Delete(ctx context.Context, req res
func (r *resourceDomainWorkspaceAssignments) diffWorkspaces(ctx context.Context, slice1, slice2 types.Set) (types.Set, diag.Diagnostics) {
s1 := make([]customtypes.UUID, 0, len(slice1.Elements()))

diags := slice1.ElementsAs(ctx, &s1, false)
if diags.HasError() {
if diags := slice1.ElementsAs(ctx, &s1, false); diags.HasError() {
return types.SetNull(customtypes.UUIDType{}), diags
}

s2 := make([]customtypes.UUID, 0, len(slice1.Elements()))

diags = slice2.ElementsAs(ctx, &s2, false)
if diags.HasError() {
if diags := slice2.ElementsAs(ctx, &s2, false); diags.HasError() {
return types.SetNull(customtypes.UUIDType{}), diags
}

Expand Down Expand Up @@ -350,5 +349,24 @@ func (r *resourceDomainWorkspaceAssignments) list(ctx context.Context, model *re
return diags
}

return model.setWorkspaces(ctx, respList)
workspaceIDs, diags := getWorkspaceIDs(ctx, *model)
if diags.HasError() {
return diags
}

elements := make([]string, 0, len(respList))

for _, element := range respList {
elements = append(elements, *element.ID)
}

var values []string

for _, workspaceID := range workspaceIDs {
if slices.Contains(elements, workspaceID) {
values = append(values, workspaceID)
}
}

return model.setWorkspaces(ctx, values)
}