msgraph-beta-sdk-go icon indicating copy to clipboard operation
msgraph-beta-sdk-go copied to clipboard

No OData route exists that match template - deviceManagement/assignmentFilters

Open ShocOne opened this issue 7 months ago • 0 comments

Describe the bug

Hi there, i am writing a terraform provider on top of your SDK. My work initially is starting with a simple object to test the provider with. I have chosen graph beta deviceManagement/assignmentFilters.

I have successfully implemented all of the CRUD functions for this resource apart from the update function which gives me errors i believe related to the SDK. The full set of crud function can be found here.

I am trying to update resources once created using the http PATCH method as follows:

// Update handles the Update operation.
func (r *AssignmentFilterResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
	var plan AssignmentFilterResourceModel

	tflog.Debug(ctx, fmt.Sprintf("Starting Update of resource: %s_%s", r.ProviderTypeName, r.TypeName))

	resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
	if resp.Diagnostics.HasError() {
		return
	}

	updateTimeout, diags := plan.Timeouts.Update(ctx, 30*time.Second)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
	ctx, cancel := context.WithTimeout(ctx, updateTimeout)
	defer cancel()

	requestBody, err := constructResource(ctx, &plan)
	if err != nil {
		resp.Diagnostics.AddError(
			"Error constructing assignment filter",
			fmt.Sprintf("Could not construct resource: %s_%s: %s", r.ProviderTypeName, r.TypeName, err.Error()),
		)
		return
	}

	_, err = r.client.DeviceManagement().AssignmentFilters().ByDeviceAndAppManagementAssignmentFilterId(plan.ID.ValueString()).Patch(ctx, requestBody, nil)
	if err != nil {
		common.HandleUpdateStateError(ctx, resp, r, &plan, err)
		return
	}

	resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)

	tflog.Debug(ctx, fmt.Sprintf("Finished Update Method: %s_%s", r.ProviderTypeName, r.TypeName))
}

My issue i believe this is due to incorrect URL construction. Is this something occurring at the SDK level, or am i incorrectly constructing my call with the PATCH method ? Any help appreciated.

thank you

Expected behavior

A well form PATCH request should be sent and update the resource via graph

How to reproduce

Go to provider, compile, create a resource using example from examples folder in HCL. Then change an attribute of the deviceAssignmentFiler and run terraform apply.

SDK Version

v0.106.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log i get the following error returned ``` 2024-07-25T19:53:34.109+0100 [ERROR] vertex "microsoft365_graph_beta_device_and_app_management_assignment_filter.example" error: Error updating resource

╷ │ Error: Error updating resource │ │ with microsoft365_graph_beta_device_and_app_management_assignment_filter.example, │ on microsoft365_graph_beta_device_and_app_management_assignment_filter.tf line 1, in resource "microsoft365_graph_beta_device_and_app_management_assignment_filter" "example": │ 1: resource "microsoft365_graph_beta_device_and_app_management_assignment_filter" "example" { │ │ Could not update with ID : No OData route exists that match template ~/singleton/navigation with http verb │ PATCH for request │ /GnT/StatelessPayloadLinkingService/8d87088f-ffff-3257-0602-071717505659/deviceManagement/assignmentFilters. ╵

</details>


### Configuration

- OS: macOS

### Other information

_No response_

ShocOne avatar Jul 25 '24 19:07 ShocOne