diff --git a/pkg/config-api-provider/provider/resources/group.go b/pkg/config-api-provider/provider/resources/group.go index 71aeefa4..924fd300 100644 --- a/pkg/config-api-provider/provider/resources/group.go +++ b/pkg/config-api-provider/provider/resources/group.go @@ -56,6 +56,7 @@ func (r *groupResource) Schema(_ context.Context, _ resource.SchemaRequest, resp // UXI business logic does not permit moving of groups stringplanmodifier.RequiresReplace(), }, + Computed: true, }, }, } @@ -91,7 +92,7 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, } groups_post_request := config_api_client.NewGroupsPostRequest(plan.Name.ValueString()) - if !plan.ParentGroupId.IsUnknown() { + if !plan.ParentGroupId.IsUnknown() && !plan.ParentGroupId.IsNull() { groups_post_request.SetParentId(plan.ParentGroupId.ValueString()) } request := r.client.ConfigurationAPI.GroupsPostUxiV1alpha1GroupsPost(ctx).GroupsPostRequest(*groups_post_request) @@ -139,7 +140,7 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp } if len(groupResponse.Items) != 1 { - resp.Diagnostics.AddError(errorSummary, "Could not find specified resource") + resp.State.RemoveResource(ctx) return } group := groupResponse.Items[0] diff --git a/pkg/config-api-provider/provider/resources/network_group_assignment.go b/pkg/config-api-provider/provider/resources/network_group_assignment.go index 7b4a3b44..7540ef4a 100644 --- a/pkg/config-api-provider/provider/resources/network_group_assignment.go +++ b/pkg/config-api-provider/provider/resources/network_group_assignment.go @@ -140,7 +140,7 @@ func (r *networkGroupAssignmentResource) Read(ctx context.Context, req resource. } if len(networkGroupAssignmentResponse.Items) != 1 { - resp.Diagnostics.AddError(errorSummary, "Could not find specified resource") + resp.State.RemoveResource(ctx) return } networkGroupAssignment := networkGroupAssignmentResponse.Items[0] diff --git a/pkg/config-api-provider/provider/resources/sensor.go b/pkg/config-api-provider/provider/resources/sensor.go index e804b234..fa0a4db4 100644 --- a/pkg/config-api-provider/provider/resources/sensor.go +++ b/pkg/config-api-provider/provider/resources/sensor.go @@ -138,7 +138,7 @@ func (r *sensorResource) Read(ctx context.Context, req resource.ReadRequest, res } if len(sensorResponse.Items) != 1 { - resp.Diagnostics.AddError(errorSummary, "Could not find specified resource") + resp.State.RemoveResource(ctx) return } sensor := sensorResponse.Items[0] diff --git a/pkg/config-api-provider/provider/resources/wired_network.go b/pkg/config-api-provider/provider/resources/wired_network.go index 882137af..9735a0e4 100644 --- a/pkg/config-api-provider/provider/resources/wired_network.go +++ b/pkg/config-api-provider/provider/resources/wired_network.go @@ -103,7 +103,7 @@ func (r *wiredNetworkResource) Read(ctx context.Context, req resource.ReadReques } if len(networkResponse.Items) != 1 { - resp.Diagnostics.AddError(errorSummary, "Could not find specified resource") + resp.State.RemoveResource(ctx) return } diff --git a/pkg/config-api-provider/provider/resources/wireless_network.go b/pkg/config-api-provider/provider/resources/wireless_network.go index eb0a6c0f..9e3104ac 100644 --- a/pkg/config-api-provider/provider/resources/wireless_network.go +++ b/pkg/config-api-provider/provider/resources/wireless_network.go @@ -103,7 +103,7 @@ func (r *wirelessNetworkResource) Read(ctx context.Context, req resource.ReadReq } if len(networkResponse.Items) != 1 { - resp.Diagnostics.AddError(errorSummary, "Could not find specified resource") + resp.State.RemoveResource(ctx) return } diff --git a/pkg/config-api-provider/test/resources/group_test.go b/pkg/config-api-provider/test/resources/group_test.go index 9e95a320..002cfa19 100644 --- a/pkg/config-api-provider/test/resources/group_test.go +++ b/pkg/config-api-provider/test/resources/group_test.go @@ -310,7 +310,7 @@ func TestGroupResourceHttpErrorHandling(t *testing.T) { } `, - ExpectError: regexp.MustCompile(`Could not find specified resource`), + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, // Create 4xx { diff --git a/pkg/config-api-provider/test/resources/network_group_assignment_test.go b/pkg/config-api-provider/test/resources/network_group_assignment_test.go index 82430724..7f12cd84 100644 --- a/pkg/config-api-provider/test/resources/network_group_assignment_test.go +++ b/pkg/config-api-provider/test/resources/network_group_assignment_test.go @@ -678,7 +678,7 @@ func TestNetworkGroupAssignmentResourceHttpErrorHandling(t *testing.T) { id = "network_group_assignment_uid" } `, - ExpectError: regexp.MustCompile(`Could not find specified resource`), + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, // Read 5xx error { diff --git a/pkg/config-api-provider/test/resources/sensor_test.go b/pkg/config-api-provider/test/resources/sensor_test.go index 59bbadae..30232685 100644 --- a/pkg/config-api-provider/test/resources/sensor_test.go +++ b/pkg/config-api-provider/test/resources/sensor_test.go @@ -257,7 +257,7 @@ func TestSensorResourceHttpErrorHandling(t *testing.T) { id = "uid" }`, - ExpectError: regexp.MustCompile(`Could not find specified resource`), + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, }, }) diff --git a/pkg/config-api-provider/test/resources/wired_network_test.go b/pkg/config-api-provider/test/resources/wired_network_test.go index 0ea1c5bc..e8533016 100644 --- a/pkg/config-api-provider/test/resources/wired_network_test.go +++ b/pkg/config-api-provider/test/resources/wired_network_test.go @@ -140,7 +140,7 @@ func TestWiredNetworkResourceHttpErrorHandling(t *testing.T) { to = uxi_wired_network.my_wired_network id = "uid" }`, - ExpectError: regexp.MustCompile(`Could not find specified resource`), + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, { PreConfig: func() { diff --git a/pkg/config-api-provider/test/resources/wireless_network_test.go b/pkg/config-api-provider/test/resources/wireless_network_test.go index 486550f0..c2b47e6a 100644 --- a/pkg/config-api-provider/test/resources/wireless_network_test.go +++ b/pkg/config-api-provider/test/resources/wireless_network_test.go @@ -147,7 +147,7 @@ func TestWirelessNetworkResourceHttpErrorHandling(t *testing.T) { to = uxi_wireless_network.my_wireless_network id = "uid" }`, - ExpectError: regexp.MustCompile(`Could not find specified resource`), + ExpectError: regexp.MustCompile(`Error: Cannot import non-existent remote object`), }, { PreConfig: func() {