Azure Custom resource provider - custom error message to ARM template - azure

If my custom resource provider wants to return a custom failure message to ARM, what should be my response body?
I have a custom resource provider backed by a JavaScript Azure function
I tried the following
body = {
error: {
code: "Failed",
message: "A custom error message'."
}
};
httpStatus = 200;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
The ARM template deployment fails with error -
{
"error": {
"code": "ResourceDeploymentFailure",
"message": "The response for resource had empty or invalid content."
}
I also tried
body = {
properties: {
provisioningState: "Failed",
error: {
code: "Failed",
message: "A custom error message'."
}
}
};
httpStatus = 200;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
The ARM template deployment fails with error
"The resource operation completed with terminal provisioning state 'Failed"
I want the ARM template deployment to fail with a custom error message I return form the Azure function - "A custom error message'."
Edited:
Here is my ARM template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourcePrefix": {
"type": "string",
"defaultValue": "prfx-",
"maxLength": 6,
"metadata": {
"description": "The prefix of HLF resource."
}
},
"randomGuid": {
"defaultValue": "[newGuid()]",
"type": "string",
"metadata": {
"description": "New random GUID"
}
}
},
"variables": {
"funcName": "[concat(parameters('resourcePrefix'), substring(parameters('randomGuid'), 0, 5))]",
"myResourceProvider": "my-custom-provider",
"location": "[resourceGroup().location]"
},
"resources": [
{
"apiVersion": "2018-09-01-preview",
"type": "Microsoft.CustomProviders/resourceProviders",
"name": "[variables('myResourceProvider')]",
"location": "[variables('location')]",
"properties": {
"resourceTypes": [
{
"name": "deploy",
"routingType": "Proxy",
"endpoint": "<azure-func-url>"
}
]
}
},
{
"apiVersion": "2018-09-01-preview",
"type": "Microsoft.CustomProviders/resourceProviders/deploy",
"name": "[concat(variables('myResourceProvider'), '/', variables('funcName'))]",
"location": "[variables('location')]",
"dependsOn": [
"[concat('Microsoft.CustomProviders/resourceProviders/',variables('myResourceProvider'))]"
]
}
],
"outputs": {
}
}

Proxying the error message as is, is not currently supported for Custom Providers. The custom error message would be nested as details under a standard message.
However, it looks like there is a bug that is stopping the propagation of the error through the ARM template. This should be fixed soon!

#jjbfour is right. The custom message is nested under "Downstream" label in the propagated message. But that is fine for me. The following works
body = {
error: {
code: "Failed",
message: "A custom error message'."
}
};
httpStatus = 400;
context.res = {
status: httpStatus,
headers: {
'Content-Type': 'application/json'
},
body: body
};
The mistake I was making earlier was not setting the HTTP status correctly.

Related

Update Assignee when Jira ticket is created using Azure logic app

I have task for automating ticket assignee on Jira using Azure logic app. When new ticket is created Azure logic app will trigger it and assign ticket to a user.
I tried using the HTTP connector to update the ticket assignee but I got Bad Request
URL:
https://company.atlassian.net/rest/api/2/{issue_Key}
Body:
"fields": {
"assignee": {
"name": "employee name"
}
}
}
I don't know how it is done via the API.
I used JSM automations to solve the problem.
I created an automation within JSM which will update the ticket when it is moved to active and also syncs the assignee.
Maybe you can try something like that :)
After reproducing from my end, I could get this work only after including the accountId along with emailAddress in the request body. Below is the complete request body in my logic app flow.
{
"fields": {
"assignee": {
"accountId": "63f32c...",
"emailAddress": "<YOUR_EMAIL_ADDRESS>"
}
}
}
Results:
In Logic App run:
In Jira dashboard:
Below is the complete code of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HTTP": {
"inputs": {
"authentication": {
"password": "yyy",
"type": "Basic",
"username": "yyy"
},
"body": {
"fields": {
"assignee": {
"accountId": "63f32c...",
"emailAddress": "yyy"
}
}
},
"method": "PUT",
"uri": "https://yyy.atlassian.net/rest/api/2/issue/10004"
},
"runAfter": {},
"type": "Http"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Cannot determine where this terraform apply error occurs

I'm getting the following error when I do a terraform apply, Error: validating Template Deployment "uksfe-dev-api-office365" (Resource Group "app-sfe-dev-eastus"): requesting validating: resources.DeploymentsClient#Validate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidRequestContent" Message="The request content was invalid and could not be deserialized: 'Error converting value \"sfe-dev-api-office365\" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.connections_office365_name', line 1, position 1590.'.".
Here is the resource the error references:
resource "azurerm_resource_group_template_deployment" "office365" {
name = format( "%s%s-%s-api-office365", var.sfe_names.market, var.sfe_names.product_group, var.sfe_names.environment)
resource_group_name = module.resource_group.name
template_content = file("./refScript/logicapp/Office365.json")
deployment_mode = "Incremental"
parameters_content = jsonencode({
"connections_office365_name" = format( "%s-%s-api-office365", var.sfe_names.product_group, var.sfe_names.environment),
"subscription_id" = data.azurerm_subscription.current.subscription_id
})
}
And here is the ARM template file referenced by the resource shown above, Office365.json:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"connections_office365_name": {
"defaultValue": "testoffice365",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[parameters('connections_office365_name')]",
"location": "eastus",
"kind": "V1",
"properties": {
"displayName": "rsgfileexchange#mycompanydomain.com",
"statuses": [
{
"status": "Connected"
}
],
"customParameterValues": {},
"nonSecretParameterValues": {},
"createdTime": "2021-03-25T07:41:30.7103666Z",
"changedTime": "2021-09-02T19:26:09.2638641Z",
"api": {
"name": "sfe-dev-api-office365",
"displayName": "Office 365 Outlook",
"description": "Microsoft Office 365 is a cloud-based service that is designed to help meet your organization's needs for robust security, reliability, and user productivity.",
"iconUri": "https://connectoricons-prod.azureedge.net/releases/v1.0.1507/1.0.1507.2528/office365/icon.png",
"brandColor": "#0078D4",
"id": "/subscriptions/dfdbeere-dfda-ghgh-eree-18a838e6ed7a/providers/Microsoft.Web/locations/eastus/managedApis/office365",
"type": "Microsoft.Web/locations/managedApis"
},
"testLinks": [
{
"requestUri": "[concat('https://management.azure.com:443/subscriptions/dfdbeere-dfda-ghgh-eree-18a838e6ed7a/resourceGroups/app-sfe-dev-eastus/providers/Microsoft.Web/connections/', parameters('connections_office365_name'), '/extensions/proxy/testconnection?api-version=2016-06-01')]",
"method": "get"
}
]
}
}
]
}
I believe the last part of the error message tells where the error occurred, i.e. Path 'properties.parameters.connections_office365_name', line 1, position 1590.'
Any help would be most appreciated.
The example here shows that parameters are passed to the template like this:
parameters_content = jsonencode({
"vnetName" = {
value = local.vnet_name
}
})
So, your code would need to be modified as follows:
parameters_content = jsonencode({
"connections_office365_name" = { value = format( "%s-%s-api-office365", var.sfe_names.product_group, var.sfe_names.environment) }
"subscription_id" = { value = data.azurerm_subscription.current.subscription_id }
})

Sharepoint online GraphAPI create list with invalid request

I am trying to create a list with in a site using the graph API.
URL: https://graph.microsoft.com/v1.0/sites/{tenantsharepoint.com}:/sites/{siteName}:/lists
Request Body:
{
"displayName": "Books",
"columns": [
{
"name": "Author",
"text": { }
},
{
"name": "PageCount",
"number": { }
}
],
"list": {
"template": "genericList"
}
}
It was working fine but all of sudden it started giving me below exception:
{
"error": {
"code": "invalidRequest",
"message": "Provided identifier is malformed - site collection id is not valid",
"innerError": {
"date": "2020-07-31T05:28:46",
"request-id": "302c5ee3-3799-4a24-a2a3-185d7801f78a"
}
}
}
Any pointers leads would be appreciated.

Can't deploy arm template with NotificationHub + ApnsCredentials

I am using arm template to deploy Azure NotificationHub
Here is
{
"apiVersion": "2017-04-01",
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs",
"name": "[parameters('notificationHub_name')]",
"location": "[parameters('location')]",
"properties": {
"GcmCredential": {
"properties": {
"googleApiKey": "[parameters('googleApiKey')]",
"gcmEndpoint": "[parameters('googleEndpoint')]"
}
},
"ApnsCredential": {
"properties": {
"appId": "[parameters('apnsAppId')]",
"appName": "[parameters('apnsAppNameId')]",
"keyId": "[parameters('apnsKeyId')]",
"token": "[parameters('apnsToken')]",
"endpoint": "[parameters('apnsEndpoint')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('notificationHub_namespace'))]"
]
}
But I got error without details BadRequest
{
"code": "DeploymentFailed",
"details": [
{
"code": "BadRequest",
"message": {
"error": {
"message": "Bad Request",
"code": "BadRequest"
}
}
]
}
I test my parameters from azure portal and it works - so I assume that parameters are correct.
The question is how to deploy NotificationHub with ApnsCredentials using ARM?
Above arm template is correct.
My parameters were bad.
I found solution by previewing requests sent from azure portal.
I was using endpoints for certificates:
Sandbox endpoint: gateway.sandbox.push.apple.com,
Production endpoint: gateway.push.apple.com
Endpoints for token authorization are different :
Sandbox Endpoint: https://api.development.push.apple.com:443/3/device
Production Endpoint: https://api.push.apple.com:443/3/device
Here you can find details:
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-http2-token-authentification#configure-via-management-api-rest

ARM template error 'properties.api' is not valid from parameter file?

I have created parameter file for LogicApp project.
When I try to deploy using this parameter file it is giving following error -
Template deployment returned the following errors:
Resource MICROSOFT.WEB/CONNECTIONS 'demo-sbs' failed with message '{
"error": {
"code": "InvalidRequestContent",
"message": "The request content is not valid and could not be deserialized: 'The 'id' property 'aaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaa/providers/Microsoft.Web/locations/westeurope/managedApis/servicebus' under 'properties.api' is not valid.'."
}
}'
LogicApp.dev.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logicAppName": {
"value": "demoapp"
},
"ResourceGroupName": {
"value": "demo1"
},
"logicAppLocation": {
"value": "westeurope"
},
"logicAppEnvironment": {
"value": "DEV"
},
"sbs_Name": {
"value": "demo-sbs"
},
"sbs_Connection_Name": {
"value": "demo-sbs"
},
"sbs_Connection_DisplayName": {
"value": "demo-sbs"
},
"nok_cb2b_we_sbs_connectionString": {
"value": "Endpoint=sb://demo-sbs.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=asdasd/assasad"
},
"LogicAppIntegrationAccountName": {
"value": "intdemo"
},
"subscriptionId": {
"value": "aaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaa"
}
}
}
LogicApp.json (resources section)
"resources": [
{
"type": "MICROSOFT.WEB/CONNECTIONS",
"apiVersion": "2016-06-01",
"name": "[parameters('demo-sbs_Connection_Name')]",
"location": "[parameters('logicAppLocation')]",
"properties": {
"api": {
"id": "[concat(parameters('subscriptionId'), '/providers/Microsoft.Web/locations/', parameters('logicAppLocation'), '/managedApis/', 'servicebus')]"
},
"displayName": "[parameters('demo-sbs_Connection_DisplayName')]",
"parameterValues": {
"connectionString": "[parameters('demo-sbs_connectionString')]"
}
}
}
the problem is with below line -
when I tried to use parameter for subscriptionId like concat(parameters('subscriptionId') it give above error and if I use concat(subscription().id it works fine.
I want to use parameter for subscriptionId also.
This is the correct syntax for what you are doing:
"api":{
"id":"[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/serviceBus')]"
}
Well, thats because thats not how resource id looks like in azure.
/subscriptions/subscription_guid/resourceGroups/resource_group_name/providers/microsoft.insights/components/resource_name
this is how it looks. to créate it you could use resourceId function. Link
Or you can use concat, but you would need to créate the same string, you can use resourceGroup().id to help you with that.

Resources