Skip to content

Commit

Permalink
Merge pull request Azure#6712 from jjbfour/jjbfour/101customrpwithlog…
Browse files Browse the repository at this point in the history
…icapp

Add 101 Sample for Custom Providers with Logic App
  • Loading branch information
bmoore-msft authored Jan 8, 2020
2 parents c400a9d + 0ef66fe commit aa96eb5
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 0 deletions.
88 changes: 88 additions & 0 deletions 101-custom-rp-with-logicapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Creating a Custom Resources for templates with Custom Providers

<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/PublicLastTestDate.svg" />&nbsp;
<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/PublicDeployment.svg" />&nbsp;

<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/FairfaxLastTestDate.svg" />&nbsp;
<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/FairfaxDeployment.svg" />&nbsp;

<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/BestPracticeResult.svg" />&nbsp;
<IMG SRC="https://azurequickstartsservice.blob.core.windows.net/badges/101-custom-rp-with-logicapp/CredScanResult.svg" />&nbsp;

<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-custom-rp-with-logicapp%2Fazuredeploy.json" target="_blank">
<img src="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.png"/>
</a>
<a href="http://armviz.io/#/?load=https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-custom-rp-with-logicapp%2Fazuredeploy.json" target="_blank">
<img src="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/visualizebutton.png"/>
</a>

This sample Azure Resource Manager template deploys a custom resource provider to Azure that extends the Azure Resource Manager API. In this sample, the custom resource provider is powered by an Azure Logic App, but any public API endpoint can be used.

The custom resource provider is a hidden Azure resource so to confirm that the custom resource provider has been deployed you will have to check the box that says *Show hidden types* in the Azure portal Overview page for the resource group.

![](images/showhidden.png)

## Details on the custom resource provider created

This sample deployment creates the following apis on the resource.

1) An Azure Resource Manager extended API called "customResources"

### CustomResources

"customResources" is an API extension contained within the custom resource provider. This extension is defined in the following part of the ARM template under the "resourceProviders" resource:

```json
"resourceTypes": [
{
"name": "customResources",
"mode": "Secure",
"routingType": "Webhook,Cache",
"endpoint": "[listCallbackURL(concat(resourceId('Microsoft.Logic/workflows', parameters('logicAppName')), '/triggers/CustomProviderWebhook'), '2017-07-01').value]"
}
]
```

| Property | Required | Description |
|---|---|---|
| name | *yes* | The name is the new "resourceType" extension that is added to the Azure Resource Manager API. This extension is instanced to the custom resource provider. Example: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/**customResources**/{customResourceName} |
| mode | *no* | Hides the **endpoint** property on reads if set to "Secure". |
| routingType | *no* | Determines the HTTP structure and strategy for HTTP requests to the **endpoint**. The property is structured as flags. The "Webhook" flag changes all requests to *POST*. The "Cache" flag allows the custom provider to store request responses and automatically return them on subsequent *GET* requests. |
| endpoint | *yes* | The public HTTP endpoint that handles all incoming reuqests. |

In the above template, we can see that the "customResources" API has been defined as a "Webhook,Cache" resource which means that it is backed by a Webhook API endpoint. In this sample, we set the callback URL for the Azure Logic App to handle the incoming request and provide a response. Because we defined the "Cache" flag, the endpoint only needs to handle the PUT and DELETE calls, while the GET calls will automatically be handled by the custom provider. In the above case, the following calls will be added to the Azure Resource Manager API:

```
(PUT|GET|DELETE) /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/customResources/{customResourceName}?api-version=2018-09-01-preview
```

The Azure Resource Manager template also utilizes the new Azure extension to create an instance of the "customResources":

```json
{
"type": "Microsoft.CustomProviders/resourceProviders/customResources",
"apiVersion": "2018-09-01-preview",
"name": "[concat(parameters('customResourceProviderName'), '/', parameters('customResourceName'))]",
"location": "[parameters('location')]",
"properties": {
"myCustomInputProperty": "myCustomInputValue",
"myCustomInputObject": {
"Property1": "Value1"
}
},
"dependsOn": [
"[concat('Microsoft.CustomProviders/resourceProviders/', parameters('customResourceProviderName'))]"
]
}
```

Navigating to the deployment details on the Azure Resource Manager template will show a new resource type called resourceproviders/customResources created on the custom resource provider.
![](images/createdcustomresource.PNG)

The outputs section of the template deployment also will display the created resource, which can be accessed through the *reference* template function.
![](images/customresourcetemplateoutput.png)

In addition, you can navigate to the deployed Azure Logic App resource in the template resource group and check the *run history* tab to see the HTTP calls.
![](images/logicapprun.png)

Additional "customResources" can be created through deploying another Azure Resource Manager Template or directly interfacing with the Azure REST API.
181 changes: 181 additions & 0 deletions 101-custom-rp-with-logicapp/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"allowedValues": [
"australiaeast",
"australiasoutheast",
"eastus",
"westus2",
"westeurope",
"northeurope",
"canadacentral",
"canadaeast",
"japaneast",
"japanwest" ],
"metadata": {
"description": "Location for the resources."
}
},
"logicAppName": {
"type": "string",
"defaultValue": "[uniqueString(resourceGroup().id)]",
"metadata": {
"description": "Name of the logic app to be created."
}
},
"customResourceProviderName": {
"type": "string",
"defaultValue": "[uniqueString(resourceGroup().id)]",
"metadata": {
"description": "Name of the custom provider to be created."
}
},
"customResourceName": {
"type": "string",
"defaultValue": "myDemoCustomResource",
"metadata": {
"description": "Name of the custom resource that is being created."
}
}
},
"resources": [
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2019-05-01",
"name": "[parameters('logicAppName')]",
"location": "[parameters('location')]",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Switch": {
"cases": {
"CreateResource": {
"actions": {
"CreateCustomResource": {
"inputs": {
"body": {
"properties": "@addProperty(triggerBody().Body['properties'], 'myDynamicProperty', 'myDynamicValue')"
},
"statusCode": 200
},
"kind": "Http",
"type": "Response"
}
},
"case": "CREATE"
}
},
"default": {
"actions": {
"DefaultHttpResponse": {
"inputs": {
"statusCode": 200
},
"kind": "Http",
"type": "Response"
}
}
},
"expression": "@triggerBody().operationType",
"type": "Switch"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"CustomProviderWebhook": {
"inputs": {
"schema": {
"required": [
"OperationType",
"ResourceType",
"ResourceId",
"ResourceName",
"Body"
],
"properties": {
"OperationType": {
"$id": "#/properties/OperationType",
"type": "string",
"enum": [
"CREATE",
"DELETE",
"GET",
"LIST",
"TRIGGER"
]
},
"ResourceType": {
"$id": "#/properties/ResourceType",
"type": "string"
},
"ResourceId": {
"$id": "#/properties/ResourceId",
"type": "string"
},
"ResourceName": {
"$id": "#/properties/ResourceName",
"type": "string"
},
"Body": {
"$id": "#/properties/Body",
"type": "object"
}
}
}
},
"kind": "Http",
"type": "Request"
}
}
}
}
},
{
"type": "Microsoft.CustomProviders/resourceProviders",
"apiVersion": "2018-09-01-preview",
"name": "[parameters('customResourceProviderName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Logic/workflows', parameters('logicAppName'))]"
],
"properties": {
"resourceTypes": [
{
"name": "customResources",
"mode": "Secure",
"routingType": "Webhook,Cache",
"endpoint": "[listCallbackURL(resourceId('Microsoft.Logic/workflows/triggers', parameters('logicAppName'), 'CustomProviderWebhook'), '2019-05-01').value]"
}
]
}
},
{
"type": "Microsoft.CustomProviders/resourceProviders/customResources",
"apiVersion": "2018-09-01-preview",
"name": "[concat(parameters('customResourceProviderName'), '/', parameters('customResourceName'))]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.CustomProviders/resourceProviders', parameters('customResourceProviderName'))]"
],
"properties": {
"myCustomInputProperty": "myCustomInputValue",
"myCustomInputObject": {
"Property1": "Value1"
}
}
}
],
"outputs": {
"customResource": {
"type": "object",
"value": "[reference(parameters('customResourceName'), '2018-09-01-preview', 'Full')]"
}
}
}
12 changes: 12 additions & 0 deletions 101-custom-rp-with-logicapp/azuredeploy.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "eastus"
},
"customResourceName": {
"value": "myCustomResourceName"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 101-custom-rp-with-logicapp/images/showhidden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions 101-custom-rp-with-logicapp/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#",
"type": "QuickStart",
"environments": [
"AzureCloud"
],
"itemDisplayName": "Create a Custom Resource for templates with Custom Providers",
"description": "This sample shows how to add custom resources to Resource Manager Templates using custom providers and logic apps.",
"summary": "This sample shows how to add custom resources to Resource Manager Templates using custom providers and logic apps.",
"githubUsername": "jjbfour",
"dateUpdated": "2019-11-04"
}

0 comments on commit aa96eb5

Please sign in to comment.