|
| 1 | +--- |
| 2 | +title: Use Azure Resource Manager templates to create Automation account | Microsoft Docs |
| 3 | +description: You can use an Azure Resource Manager template to create an Azure Automation account. |
| 4 | +ms.service: automation |
| 5 | +ms.subservice: update-management |
| 6 | +ms.topic: conceptual |
| 7 | +author: mgoedtel |
| 8 | +ms.author: magoedte |
| 9 | +ms.date: 04/15/2020 |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +# Create Automation account using Azure Resource Manager template |
| 14 | + |
| 15 | +You can use [Azure Resource Manager templates](../azure-resource-manager/templates/template-syntax.md) to create an Azure Automation account in your resource group. This article provides a sample template that automates the following: |
| 16 | + |
| 17 | +* Creation of a Azure Monitor Log Analytics workspace. |
| 18 | +* Creation of an Azure Automation account. |
| 19 | +* Links the Automation account to the Log Analytics workspace. |
| 20 | + |
| 21 | +The template does not automate the onboarding of one or more Azure or non-Azure VMs, or solutions. |
| 22 | + |
| 23 | +>[!NOTE] |
| 24 | +>Creation of the Automation Run As account is not supported when using an Azure Resource Manager template. To create a Run As account manually from the portal or with PowerShell, see [Manage Run As account](manage-runas-account.md). |
| 25 | +
|
| 26 | +## API versions |
| 27 | + |
| 28 | +The following table lists the API version for the resources used in this example. |
| 29 | + |
| 30 | +| Resource | Resource type | API version | |
| 31 | +|:---|:---|:---| |
| 32 | +| Workspace | workspaces | 2017-03-15-preview | |
| 33 | +| Automation account | automation | 2015-10-31 | |
| 34 | + |
| 35 | +## Before using the template |
| 36 | + |
| 37 | +If you choose to install and use PowerShell locally, this article requires the Azure PowerShell Az module. Run `Get-Module -ListAvailable Az` to find the version. If you need to upgrade, see [Install the Azure PowerShell module](/powershell/azure/install-az-ps). If you are running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure. With Azure PowerShell, deployment uses [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment). |
| 38 | + |
| 39 | +If you choose to install and use the CLI locally, this article requires that you are running the Azure CLI version 2.1.0 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest). With Azure CLI, this deployment uses [az group deployment create](https://docs.microsoft.com/cli/azure/group/deployment?view=azure-cli-latest#az-group-deployment-create). |
| 40 | + |
| 41 | +The JSON template is configured to prompt you for: |
| 42 | + |
| 43 | +* The name of the workspace |
| 44 | +* The region to create the workspace in |
| 45 | +* The name of the Automation account |
| 46 | +* The region to create the account in |
| 47 | + |
| 48 | +The JSON template specifies a default value for the other parameters that would likely be used as a standard configuration in your environment. You can store the template in an Azure storage account for shared access in your organization. For further information about working with templates, see [Deploy resources with Resource Manager templates and Azure CLI](../azure-resource-manager/templates/deploy-cli.md). |
| 49 | + |
| 50 | +The following parameters in the template are set with a default value for the Log Analytics workspace: |
| 51 | + |
| 52 | +* sku - defaults to the new Per-GB pricing tier released in the April 2018 pricing model |
| 53 | +* data retention - defaults to thirty days |
| 54 | +* capacity reservation - defaults to 100 GB |
| 55 | + |
| 56 | +>[!WARNING] |
| 57 | +>If creating or configuring a Log Analytics workspace in a subscription that has opted into the new April 2018 pricing model, the only valid Log Analytics pricing tier is **PerGB2018**. |
| 58 | +> |
| 59 | +
|
| 60 | +>[!NOTE] |
| 61 | +>Before using this template, review [additional details](../azure-monitor/platform/template-workspace-configuration.md#create-a-log-analytics-workspace) to fully understand workspace configuration options such as access control mode, pricing tier, retention, and capacity reservation level. If you are new to Azure Monitor logs and have not deployed a workspace already, you should review the [workspace design](../azure-monitor/platform/design-logs-deployment.md) guidance to learn about access control, and an understanding of the design implementation strategies we recommend for your organization. |
| 62 | +
|
| 63 | +## Deploy template |
| 64 | + |
| 65 | +1. Copy and paste the following JSON syntax into your file: |
| 66 | + |
| 67 | + ```json |
| 68 | + { |
| 69 | + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", |
| 70 | + "contentVersion": "1.0.0.0", |
| 71 | + "parameters": { |
| 72 | + "workspaceName": { |
| 73 | + "type": "string", |
| 74 | + "metadata": { |
| 75 | + "description": "Workspace name" |
| 76 | + } |
| 77 | + }, |
| 78 | + "sku": { |
| 79 | + "type": "string", |
| 80 | + "allowedValues": [ |
| 81 | + "pergb2018", |
| 82 | + "Free", |
| 83 | + "Standalone", |
| 84 | + "PerNode", |
| 85 | + "Standard", |
| 86 | + "Premium" |
| 87 | + ], |
| 88 | + "defaultValue": "pergb2018", |
| 89 | + "metadata": { |
| 90 | + "description": "Pricing tier: perGB2018 or legacy tiers (Free, Standalone, PerNode, Standard or Premium) which are not available to all customers." |
| 91 | + } |
| 92 | + }, |
| 93 | + "dataRetention": { |
| 94 | + "type": "int", |
| 95 | + "defaultValue": 30, |
| 96 | + "minValue": 7, |
| 97 | + "maxValue": 730, |
| 98 | + "metadata": { |
| 99 | + "description": "Number of days of retention. Workspaces in the legacy Free pricing tier can only have 7 days." |
| 100 | + } |
| 101 | + }, |
| 102 | + "immediatePurgeDataOn30Days": { |
| 103 | + "type": "bool", |
| 104 | + "defaultValue": "[bool('false')]", |
| 105 | + "metadata": { |
| 106 | + "description": "If set to true when changing retention to 30 days, older data will be immediately deleted. Use this with extreme caution. This only applies when retention is being set to 30 days." |
| 107 | + } |
| 108 | + }, |
| 109 | + "location": { |
| 110 | + "type": "string", |
| 111 | + "allowedValues": [ |
| 112 | + "australiacentral", |
| 113 | + "australiaeast", |
| 114 | + "australiasoutheast", |
| 115 | + "brazilsouth", |
| 116 | + "canadacentral", |
| 117 | + "centralindia", |
| 118 | + "centralus", |
| 119 | + "eastasia", |
| 120 | + "eastus", |
| 121 | + "eastus2", |
| 122 | + "francecentral", |
| 123 | + "japaneast", |
| 124 | + "koreacentral", |
| 125 | + "northcentralus", |
| 126 | + "northeurope", |
| 127 | + "southafricanorth", |
| 128 | + "southcentralus", |
| 129 | + "southeastasia", |
| 130 | + "uksouth", |
| 131 | + "ukwest", |
| 132 | + "westcentralus", |
| 133 | + "westeurope", |
| 134 | + "westus", |
| 135 | + "westus2" |
| 136 | + ], |
| 137 | + "metadata": { |
| 138 | + "description": "Specifies the location in which to create the workspace." |
| 139 | + } |
| 140 | + }, |
| 141 | + "automationAccountName": { |
| 142 | + "type": "string", |
| 143 | + "metadata": { |
| 144 | + "description": "Automation account name" |
| 145 | + } |
| 146 | + }, |
| 147 | + "automationAccountLocation": { |
| 148 | + "type": "string", |
| 149 | + "metadata": { |
| 150 | + "description": "Specify the location in which to create the Automation account." |
| 151 | + } |
| 152 | + }, |
| 153 | + "sampleGraphicalRunbookName": { |
| 154 | + "type": "String", |
| 155 | + "defaultValue": "AzureAutomationTutorial" |
| 156 | + }, |
| 157 | + "sampleGraphicalRunbookDescription": { |
| 158 | + "type": "String", |
| 159 | + "defaultValue": " An example runbook which gets all the ARM resources using the Run As Account (Service Principal)." |
| 160 | + }, |
| 161 | + "sampleGraphicalRunbookContentUri": { |
| 162 | + "type": "String", |
| 163 | + "defaultValue": "https://eus2oaasibizamarketprod1.blob.core.windows.net/marketplace-runbooks/AzureAutomationTutorial.graphrunbook" |
| 164 | + }, |
| 165 | + "samplePowerShellRunbookName": { |
| 166 | + "type": "String", |
| 167 | + "defaultValue": "AzureAutomationTutorialScript" |
| 168 | + }, |
| 169 | + "samplePowerShellRunbookDescription": { |
| 170 | + "type": "String", |
| 171 | + "defaultValue": " An example runbook which gets all the ARM resources using the Run As Account (Service Principal)." |
| 172 | + }, |
| 173 | + "samplePowerShellRunbookContentUri": { |
| 174 | + "type": "String", |
| 175 | + "defaultValue": "https://eus2oaasibizamarketprod1.blob.core.windows.net/marketplace-runbooks/AzureAutomationTutorial.ps1" |
| 176 | + }, |
| 177 | + "samplePython2RunbookName": { |
| 178 | + "type": "String", |
| 179 | + "defaultValue": "AzureAutomationTutorialPython2" |
| 180 | + }, |
| 181 | + "samplePython2RunbookDescription": { |
| 182 | + "type": "String", |
| 183 | + "defaultValue": " An example runbook which gets all the ARM resources using the Run As Account (Service Principal)." |
| 184 | + }, |
| 185 | + "samplePython2RunbookContentUri": { |
| 186 | + "type": "String", |
| 187 | + "defaultValue": "https://eus2oaasibizamarketprod1.blob.core.windows.net/marketplace-runbooks/AzureAutomationTutorialPython2.py" |
| 188 | + } |
| 189 | + }, |
| 190 | + "resources": [ |
| 191 | + { |
| 192 | + "type": "Microsoft.OperationalInsights/workspaces", |
| 193 | + "name": "[parameters('workspaceName')]", |
| 194 | + "apiVersion": "2017-03-15-preview", |
| 195 | + "location": "[parameters('location')]", |
| 196 | + "properties": { |
| 197 | + "sku": { |
| 198 | + "Name": "[parameters('sku')]", |
| 199 | + "name": "CapacityReservation", |
| 200 | + "capacityReservationLevel": 100 |
| 201 | + }, |
| 202 | + "retentionInDays": "[parameters('dataRetention')]", |
| 203 | + "features": { |
| 204 | + "searchVersion": 1, |
| 205 | + "legacy": 0, |
| 206 | + "enableLogAccessUsingOnlyResourcePermissions": true |
| 207 | + } |
| 208 | + }, |
| 209 | + "resources": [ |
| 210 | + { |
| 211 | + "type": "Microsoft.Automation/automationAccounts", |
| 212 | + "apiVersion": "2015-01-01-preview", |
| 213 | + "name": "[parameters('automationAccountName')]", |
| 214 | + "location": "[parameters('automationAccountLocation')]", |
| 215 | + "dependsOn": [ |
| 216 | + "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]", |
| 217 | + ], |
| 218 | + "tags": {}, |
| 219 | + "properties": { |
| 220 | + "sku": { |
| 221 | + "name": "Basic" |
| 222 | + } |
| 223 | + }, |
| 224 | + "resources": [ |
| 225 | + { |
| 226 | + "type": "runbooks", |
| 227 | + "apiVersion": "2015-01-01-preview", |
| 228 | + "name": "[parameters('sampleGraphicalRunbookName')]", |
| 229 | + "location": "[parameters('automationAccountLocation')]", |
| 230 | + "dependsOn": [ |
| 231 | + "[concat('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]" |
| 232 | + ], |
| 233 | + "tags": {}, |
| 234 | + "properties": { |
| 235 | + "runbookType": "GraphPowerShell", |
| 236 | + "logProgress": "false", |
| 237 | + "logVerbose": "false", |
| 238 | + "description": "[parameters('sampleGraphicalRunbookDescription')]", |
| 239 | + "publishContentLink": { |
| 240 | + "uri": "[parameters('sampleGraphicalRunbookContentUri')]", |
| 241 | + "version": "1.0.0.0" |
| 242 | + } |
| 243 | + } |
| 244 | + }, |
| 245 | + { |
| 246 | + "type": "runbooks", |
| 247 | + "apiVersion": "2015-01-01-preview", |
| 248 | + "name": "[parameters('samplePowerShellRunbookName')]", |
| 249 | + "location": "[parameters('automationAccountLocation')]", |
| 250 | + "dependsOn": [ |
| 251 | + "[concat('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]" |
| 252 | + ], |
| 253 | + "tags": {}, |
| 254 | + "properties": { |
| 255 | + "runbookType": "PowerShell", |
| 256 | + "logProgress": "false", |
| 257 | + "logVerbose": "false", |
| 258 | + "description": "[parameters('samplePowerShellRunbookDescription')]", |
| 259 | + "publishContentLink": { |
| 260 | + "uri": "[parameters('samplePowerShellRunbookContentUri')]", |
| 261 | + "version": "1.0.0.0" |
| 262 | + } |
| 263 | + } |
| 264 | + }, |
| 265 | + { |
| 266 | + "type": "runbooks", |
| 267 | + "apiVersion": "2015-01-01-preview", |
| 268 | + "name": "[parameters('samplePython2RunbookName')]", |
| 269 | + "location": "[parameters('automationAccountLocation')]", |
| 270 | + "dependsOn": [ |
| 271 | + "[concat('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]" |
| 272 | + ], |
| 273 | + "tags": {}, |
| 274 | + "properties": { |
| 275 | + "runbookType": "Python2", |
| 276 | + "logProgress": "false", |
| 277 | + "logVerbose": "false", |
| 278 | + "description": "[parameters('samplePython2RunbookDescription')]", |
| 279 | + "publishContentLink": { |
| 280 | + "uri": "[parameters('samplePython2RunbookContentUri')]", |
| 281 | + "version": "1.0.0.0" |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + ] |
| 286 | + }, |
| 287 | + { |
| 288 | + "apiVersion": "2015-11-01-preview", |
| 289 | + "type": "Microsoft.OperationalInsights/workspaces/linkedServices", |
| 290 | + "name": "[concat(parameters('workspaceName'), '/' , 'Automation')]", |
| 291 | + "location": "[resourceGroup().location]", |
| 292 | + "dependsOn": [ |
| 293 | + "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]", |
| 294 | + "[concat('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]" |
| 295 | + ], |
| 296 | + "properties": { |
| 297 | + "resourceId": "[resourceId('Microsoft.Automation/automationAccounts/', parameters('automationAccountName'))]" |
| 298 | + } |
| 299 | + } |
| 300 | + ] |
| 301 | + } |
| 302 | + ] |
| 303 | + } |
| 304 | + ``` |
| 305 | + |
| 306 | +2. Edit the template to meet your requirements. Consider creating a [Resource Manager parameters file](../azure-resource-manager/templates/parameter-files.md) instead of passing parameters as inline values. |
| 307 | + |
| 308 | +3. Save this file as deployAzAutomationAccttemplate.json to a local folder. |
| 309 | + |
| 310 | +4. You are ready to deploy this template. You can use either PowerShell or the Azure CLI. When you're prompted for a workspace and Automation account name, provide a name that is globally unique across all Azure subscriptions. |
| 311 | + |
| 312 | + **PowerShell** |
| 313 | + |
| 314 | + ```powershell |
| 315 | + New-AzResourceGroupDeployment -Name <deployment-name> -ResourceGroupName <resource-group-name> -TemplateFile deployAzAutomationAccttemplate.json |
| 316 | + ``` |
| 317 | + |
| 318 | + **Azure CLI** |
| 319 | + |
| 320 | + ```cli |
| 321 | + az group deployment create --resource-group <my-resource-group> --name <my-deployment-name> --template-file deployAzAutomationAccttemplate.json |
| 322 | + ``` |
| 323 | + |
| 324 | + The deployment can take a few minutes to complete. When it finishes, you see a message similar to the following that includes the result: |
| 325 | + |
| 326 | +  |
| 327 | + |
| 328 | +## Next steps |
| 329 | + |
| 330 | +Now that you have an Automation account, you can create runbooks and automate manual processes. |
0 commit comments