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: remove from state and do null parent_uid check #46

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
5 changes: 3 additions & 2 deletions pkg/config-api-provider/provider/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/provider/resources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/test/resources/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/config-api-provider/test/resources/sensor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading