Create Webhook for Azure Automation runbook via ARM template

Christoph Distefano 101 Reputation points
2020-10-27T11:02:45.763+00:00

We need to create a Webhook to run Azure Automation runbooks via an ARM template.
The documentation states that webhooks are possible via ARM templates, as you can see in the following posts:

Documentation:

It seems like this is not supported or at least I am currently not getting it to work.
The documentation states, that the URI parameter is optional (required: no). If I leave it empty, the ARM template deployment fails with the error "Invalid URI".

Looking at the New-AzAutomationWebhook command in Debug mode shows that two requests are sent:

  1. Creation of a new WebHook Uri
    POST: https://management.azure.com/subscriptions/{subID}/resourceGroups/{rgname}/providers/Microsoft.Automation/automation
    Accounts/{automationaccountname}/webhooks/generateUri?api-version=2015-10-31
  2. Creation of the WebHook, using the previously created URI
    PUT: https://management.azure.com/subscriptions/{subID}/resourceGroups/{rgname}/providers/Microsoft.Automation/automation
    Accounts/{automationaccountname}/webhooks/{webhookname}?api-version=2015-10-31
    The body contains the URI previously created.

I am not able to get my ARM template running, and I do not see any way to create a URI for a webhook in native ARM templates. Only PowerShell / API calls could solve the issue at the moment.
Any input on how to create Webhooks for Automation Accounts via ARM are highly appreciated.

PS: the documentation also states that e.g. ExpiryTime is a non-required parameter, but you need to add it.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2021-02-26T14:12:08.073+00:00

    Hi @Leo D'Arcy ,

    We've heard back from the product team and they informed us that support this scenario is in the deployment process. It should be available across all regions by the end of next week. If after those coming days, you still experience issues with your ARM template, please feel free to either email us or '@' us down below.

    EDIT: Please see a sample ARM template below on how to create Automation Runbook. We'll be adding similar templates to the docs soon.

    {  
        "$schema": https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#,  
        "contentVersion": "1.0.0.0",  
        "parameters": {  
            "automationAccountName": {  
                "type": "String",  
                "metadata": {  
                    "description": "Automation account name"  
                }  
            },  
            "webhookName": {  
                "type": "String",  
                "metadata": {  
                    "description": "Webhook Name"  
                }  
            },  
            "runbookName": {  
                "type": "String",  
                "metadata": {  
                    "description": "Runbook Name for which webhook will be created"  
                }  
            },  
            "WebhookExpiryTime": {  
                "type": "String",  
                "metadata": {  
                    "description": "Webhook Expiry time"  
                }  
            },  
            "_artifactsLocation": {  
                "defaultValue": https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-automation/,  
                "type": "String",  
                "metadata": {  
                    "description": "URI to artifacts location"  
                }  
            }  
        },  
        "resources": [  
            {  
                "type": "Microsoft.Automation/automationAccounts",  
                "apiVersion": "2020-01-13-preview",  
                "name": "[parameters('automationAccountName')]",  
                "location": "[resourceGroup().location]",  
                "properties": {  
                    "sku": {  
                        "name": "Free"  
                    }  
                },  
                "resources": [  
                    {  
                        "type": "runbooks",  
                        "apiVersion": "2018-06-30",  
                        "name": "[parameters('runbookName')]",  
                        "location": "[resourceGroup().location]",  
                        "dependsOn": [  
                            "[parameters('automationAccountName')]"  
                        ],  
                        "properties": {  
                            "runbookType": "Python2",  
                            "logProgress": "false",  
                            "logVerbose": "false",  
                            "description": "Sample Runbook",  
                            "publishContentLink": {  
                                "uri": "[uri(parameters('_artifactsLocation'), 'scripts/AzureAutomationTutorialPython2.py')]",  
                                "version": "1.0.0.0"  
                            }  
                        }  
                    },  
                    {  
                        "type": "webhooks",  
                        "apiVersion": "2018-06-30",  
                        "name": "[parameters('webhookName')]",  
                        "dependsOn": [  
                            "[parameters('automationAccountName')]",  
                            "[parameters('runbookName')]"  
                        ],  
                        "properties": {  
                            "isEnabled": true,  
                            "expiryTime": "[parameters('WebhookExpiryTime')]",  
                            "runbook": {  
                                "name": "[parameters('runbookName')]"  
                            }  
                        }  
                    }  
                ]  
            }  
        ],  
        "outputs": {  
            "webhookUri": {  
                "type": "String",  
                "value": "[reference(parameters('webhookName')).uri]"  
            }  
        }  
    }  
    

    Regards,
    Ryan

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.