Last active
March 19, 2018 09:17
-
-
Save arcotek-ltd/7c606540980a45a3a7915ccae2e0b140 to your computer and use it in GitHub Desktop.
Azure Template: Upload and execute a PowerShell runbook in an Automation Account that is in a different resource group to the resources being deployed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"runbookParameters": { | |
"type": "object" | |
}, | |
"currentDateTimeInTicks": { | |
"type": "string", | |
"minLength": 18, | |
"maxLength": 18, | |
"metadata": { | |
"description": "The current datetime in ticks. This is used to generate a unique string for every deployment" | |
} | |
} | |
}, | |
"variables": { | |
"sharedVariables": { | |
"currentDateTimeInTicks": "[parameters('currentDateTimeInTicks')]", | |
"dsc": { | |
"automationAccountResourceGroupName": "myAA-ResourceGroup", | |
"automationAccountName": "myAutomationAccount" | |
} | |
}, | |
"automationAccountResourceGroupName": "[variables('sharedVariables').dsc.automationAccountResourceGroupName]", | |
"automationAccountName": "[variables('sharedVariables').dsc.automationAccountName]", | |
"automationAccountResourceId": "[resourceId(variables('automationAccountResourceGroupName'),'Microsoft.Automation/automationAccounts',variables('automationAccountName'))]", | |
"runbookName": "Update-ResourceGroupTags", | |
"runbookDescription": "Updates Resource Group's tags. Triggered from template during deployment", | |
"runbookUri": "https://somestorageaccount.blob.core.windows.net/acontainer/Update-ResourceGroupTags.ps1", | |
"runbookJobId": "[guid(resourceGroup().id, uniqueString(resourceGroup().id, variables('sharedVariables').currentDateTimeInTicks))]", | |
"deploymentResourceGroupId": "[resourceGroup().id]", | |
"rolesTagObject": { | |
"db": "TestVm1", | |
"Server": "TestVm1", | |
"Client": "TestVm1" | |
} | |
}, | |
"resources": [ | |
{ | |
"apiVersion": "2017-05-10", | |
"name": "[Concat('Execute_Runbook(',variables('runbookName'),')')]", | |
"type": "Microsoft.Resources/deployments", | |
"resourceGroup": "[variables('automationAccountResourceGroupName')]", | |
"properties": { | |
"mode": "Incremental", | |
"template": { | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": {}, | |
"variables": {}, | |
"resources": [ | |
{ | |
"apiversion": "2018-01-15", | |
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]", | |
"name": "[variables('automationAccountName')]", | |
"type": "Microsoft.Automation/automationAccounts", | |
"properties": { | |
"sku": { | |
"name": "Basic" | |
} | |
}, | |
"tags": { | |
"task2": "Import-Runbook_to_AA" | |
}, | |
"resources": [ | |
{ | |
"name": "[variables('runbookName')]", | |
"type": "runbooks", | |
"apiVersion": "2018-01-15", | |
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]", | |
"dependsOn": [ | |
"[concat('Microsoft.Automation/automationAccounts/', variables('AutomationAccountName'))]" | |
], | |
"tags": {}, | |
"properties": { | |
"runbookType": "PowerShell", | |
"logProgress": "false", | |
"logVerbose": "true", | |
"description": "[variables('runbookDescription')]", | |
"publishContentLink": { | |
"uri": "[variables('runbookUri')]", | |
"version": "1.0.0.0" | |
} | |
} | |
}, | |
{ | |
"name": "[variables('runbookJobId')]", | |
"type": "jobs", | |
"apiVersion": "2018-01-15", | |
"location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]", | |
"dependsOn": [ | |
"[concat('Microsoft.Automation/automationAccounts/', variables('AutomationAccountName'))]", | |
"[concat('Microsoft.Automation/automationAccounts/', variables('AutomationAccountName'), '/runbooks/',variables('runbookName'))]" | |
], | |
"tags": { | |
"JobId": "[variables('runbookJobId')]" | |
}, | |
"properties": { | |
"runbook": { | |
"name": "[variables('runbookName')]" | |
}, | |
"parameters": { | |
"ResourceGroupId": "[parameters('runbookParameters').ResourceGroupId]", | |
"MyTags": "[variable('roleTagObject')]" | |
} | |
} | |
} | |
} | |
] | |
} | |
], | |
"outputs": { | |
"testOutput": { | |
"type": "string", | |
"value": "testValue" | |
} | |
} | |
}, | |
"debugSetting": { | |
"detailLevel": "requestContent, responseContent" | |
} | |
} | |
} | |
], | |
"outputs": { | |
"runbookParameters": { | |
"type": "object", | |
"value": "[parameters('runbookParameters')]" | |
}, | |
"runbookJobId": { | |
"type": "string", | |
"value": "[variables('runbookJobId')]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment