Custom resource proxy reference
This article will go through the requirements for endpoints implementing proxy custom resources. If you're unfamiliar with Azure Custom Resource Providers, see the overview on custom resource providers.
Define a proxy resource endpoint
A proxy resource can be created by specifying the routingType
to "Proxy".
Sample custom resource provider:
{
"properties": {
"resourceTypes": [
{
"name": "myCustomResources",
"routingType": "Proxy",
"endpoint": "https://{endpointURL}/"
}
]
},
"location": "eastus",
"type": "Microsoft.CustomProviders/resourceProviders",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}",
"name": "{resourceProviderName}"
}
Build a proxy resource endpoint
An endpoint that implements a "Proxy" resource endpoint must handle the request and response for the new API in Azure. In this case, the #resourceType* will generate a new Azure resource API for PUT
, GET
, and DELETE
to perform CRUD on a single resource, as well as GET
to retrieve all existing resources.
Note
The id
, name
, and type
fields are not required, but they're needed to integrate the custom resource with an existing Azure ecosystem.
Sample resource:
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
Parameter reference:
Property | Sample | Description |
---|---|---|
name | '{myCustomResourceName}' | The name of the custom resource. |
type | 'Microsoft.CustomProviders/resourceProviders/{resourceTypeName}' | The resource type namespace. |
id | '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/ providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/ myCustomResources/{myCustomResourceName}' |
The resource ID. |
Create a custom resource
Azure API incoming request:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resource-provider-name}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
{
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
This request will then be forwarded to the endpoint in the form:
PUT https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}
{
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
The response from the endpoint is then forwarded back to the customer. The response should return:
- A valid JSON object document. All arrays and strings should be nested under a top object.
- The
Content-Type
header should be set to "application/json; charset=utf-8".
Endpoint response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
Azure Custom Resource Provider response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
Remove a custom resource
Azure API incoming request:
Delete https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
This request will then be forwarded to the endpoint in the form:
Delete https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}
The response from the endpoint is then forwarded back to the customer. The response should return:
- Valid JSON object document. All arrays and strings should be nested under a top object.
- The
Content-Type
header should be set to "application/json; charset=utf-8".
Endpoint response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Azure Custom Resource Provider response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Retrieve a custom resource
Azure API incoming request:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
This request will then be forwarded to the endpoint in the form:
GET https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}
The response from the endpoint is then forwarded back to the customer. The response should return:
- A valid JSON object document. All arrays and strings should be nested under a top object.
- The
Content-Type
header should be set to "application/json; charset=utf-8".
Endpoint response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
Azure Custom Resource Provider response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
Enumerate all custom resources
Azure API incoming request:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
This request will then be forwarded to the endpoint in the form:
GET https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources
The response from the endpoint is then forwarded back to the customer. The response should return:
- A valid JSON object document. All arrays and strings should be nested under a top object.
- The
Content-Type
header should be set to "application/json; charset=utf-8". - The list of resources should be placed under the top-level
value
property.
Endpoint response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"value" : [
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
]
}
Azure Custom Resource Provider response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"value" : [
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
]
}