Managed application list resources failing with 'resource provider returned either empty or invalid payload'

62 Views Asked by At

I'm building a managed application linked to a custom resource provider. In the managed application 'Resources (preview)' tab in Azure portal I get the below error when it tries to retrieve a list of my custom resources.

The logs in the function app providing the api indicate that it's been called and executed successfully.

The add button works fine and resources are created.

I am using a version 4 function app so have changed the provider a small amount from the examples I have seen.

Any suggestions where I might be going wrong?

EnumerateAllCustomResources function

public static async Task<IActionResult> EnumerateAllCustomResources(HttpRequest requestMessage, TableClient tableClient, string partitionKey, string resourceType, ILogger log)
{
    // Generate upper bound of the query.
    var rowKeyUpperBound = new StringBuilder(resourceType);
    rowKeyUpperBound[rowKeyUpperBound.Length - 1]++;

    log.LogInformation($"partitionKey: {partitionKey}");
    log.LogInformation($"resourceType: {resourceType}");
    log.LogInformation($"rowKeyUpperBound: {rowKeyUpperBound}");

    // The RowKey QueryComparisons.GreaterThan and QueryComparisons.LessThan is Azure Table storage syntax to perform a "startswith" query for strings.
    var queryResultsFilter = tableClient.QueryAsync<CustomResource>(filter: $"PartitionKey eq '{partitionKey}' and RowKey lt '{rowKeyUpperBound.ToString()}' and RowKey ge '{resourceType}'");
    var resources = new List<JToken>();
            
    await foreach (Page<CustomResource> page in queryResultsFilter.AsPages())
    {
        resources.AddRange(page.Values.Select(customResource => JToken.Parse(customResource.Data)));
    }

    var responseObject = new StringContent(new JObject(new JProperty("value", resources)).ToString(), System.Text.Encoding.UTF8, "application/json");

    log.LogInformation($"responseObject: {responseObject.ReadAsStringAsync().Result}");

    return new OkObjectResult(responseObject);
}

Function Logs

2023-07-22T12:16:48.199 [Information] Executing 'VMSchedule' (Reason='This function was programmatically called via the host APIs.', Id=8351e550-96e4-4c3a-adff-7606e7222ca6)
2023-07-22T12:16:48.200 [Information] The Custom Provider Function received a request 'GET' for resource '/subscriptions/xxx/resourceGroups/mrg-Cat7-20230722234117/providers/Microsoft.CustomProviders/resourceProviders/public/vmschedule'.
2023-07-22T12:16:48.200 [Information] partitionKey: xxx:mrg-Cat7-20230722234117:public
2023-07-22T12:16:48.200 [Information] resourceType: Microsoft.CustomProviders:resourceProviders:vmschedule:
2023-07-22T12:16:48.207 [Information] responseObject: {
  "value": [
    {
      "id": "/subscriptions/xxx/resourceGroups/mrg-Cat7-20230722234117/providers/Microsoft.CustomProviders/resourceProviders/public/vmschedule/Schedule1",
      "name": "Schedule1",
      "type": "Microsoft.CustomProviders/resourceProviders/vmschedule",
      "properties": {
        "myproperty": "On",
        "provisioningState": "Accepted"
      }
    }
  ]
}
2023-07-22T12:16:48.207 [Information] Executed 'VMSchedule' (Succeeded, Id=8351e550-96e4-4c3a-adff-7606e7222ca6, Duration=36ms)

Error

{
  "name": "063e78d0-34db-4c43-9228-c9b6c0736027",
  "httpStatusCode": 404,
  "headers": {
    "Pragma": "no-cache",
    "x-ms-ratelimit-remaining-subscription-reads": "11994",
    "x-ms-providerhub-traffic": "True",
    "mise-correlation-id": "90855636-0a36-49eb-9fd5-c6255941204b",
    "x-ms-request-id": "9cc4fe11-a377-48b8-90f0-852926b6c922",
    "x-ms-client-request-id": "93a554d1-f721-4456-a6c3-f0e821f1602f",
    "x-ms-failure-cause": "gateway",
    "x-ms-correlation-request-id": "16868fd5-9ffd-4727-bd40-454f8317d51e",
    "x-ms-routing-request-id": "AUSTRALIAEAST:20230722T120432Z:2adabb6b-1be0-4976-a655-8c0809b922f1",
    "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
    "X-Content-Type-Options": "nosniff",
    "Cache-Control": "no-cache",
    "Date": "Sat, 22 Jul 2023 12:04:31 GMT"
  },
  "content": {
    "error": {
      "code": "ResourceReadFailed",
      "message": "Failed to read resource '/subscriptions/56700cf2-8209-4ba3-8473-1b62b20fbe8b/resourceGroups/rg-servicecatalog/providers/' as resource provider returned either empty or invalid payload"
    }
  },
  "contentLength": 235
}
0

There are 0 best solutions below