2
votes

I need to use an existing Azure Automation Account in ARM Templates to create a new compilation job. I know how to do this when the Automation Account is in the same Resource Group where I'm deploying, but I can't figure it out when it's an existing Automation Account in a different Resource Group.

for example:

Parent Template (Resource)

{
  "name": "dscCompile",
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2016-09-01",
  "dependsOn": [
    "[resourceId('Microsoft.Resources/deployments', 'newGuid')]"
  ],
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[variables('templates').dsc]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "compile-settings": {
        "value": {
          "configurationData": "[concat('{\"AllNodes\": [{\"NodeName\":\"*\",\"PSDscAllowPlainTextPassword\":true,\"RetryIntervalSec\":30,\"RetryCount\":20},{\"Nodename\":\"localhost\",\"domainName\":\"', parameters('extn-settings').domain, '\",\"adminCreds\":\"', parameters('adminPassword'), '\",\"Role\":\"DC\"}]}')]",
          "configurationName": "createPDC",
          "location": "Australia Southeast",
          "name": "[reference('newGuid').outputs.guid.value)]"
        }
      },                    
      "tag-values": {
        "value": "[parameters('tag-values')]"
      }
    }
 }

Child Template

$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "compile-settings": {
            "type": "object",
            "metadata": {
                "description": "These are settings for a DSC Compile"
            }
        },
        "tag-values": {
            "type": "object",
            "metadata": {
                "description": "These are the Tag values"
            }
        }
    },
    "resources": [
        {
            "name": "[parameters('compile-settings').jobGuid]",
            "type": "Microsoft.Automation/automationAccounts/compilationjobs",
            "apiVersion": "2015-10-31",
            "location": "[parameters('compile-settings').location]",
            "tags": "[parameters('tag-values')]",
            "dependsOn": [],
            "properties": {
                "configuration": {
                    "name": "[parameters('compile-settings').configurationName]"
                },
                "parameters": {
                    "ConfigurationData": "[parameters('compile-settings').ConfigurationData]"
                }
            },
            "resources": []
        }       
    ],
    "outputs": {}
}

Thanks in advance!

1
so where's the code for compilation job? and I don't really understand what are you trying to achieve. onboarding isn't referencing resource group in any way. so its not needed.4c74356b41
Sorry - some how I posted code I don't recognised. I've corrected - sorry about that.mrptsai
btw, can you give me a link to an example of how to start a compilation job with a template? (with parameters), thanks!4c74356b41
I saw that, but I'm talking about the compile-settings object you are passing in (you can replace values with bogus ones, but please keep the structure if something is a complex object)4c74356b41

1 Answers

2
votes

Okay, so this wasn't even possible until recently, you can do it with cross resource group deployment.

Basically, you create a template inside a template (aka nested\child template) and pick a different resource group (using the resourceGroup property for that template. no other way.

{
    "apiVersion": "2017-05-10",
    "name": "nestedTemplate",
    "type": "Microsoft.Resources/deployments",
    "resourceGroup": "crossResourceGroupDeployment",
    "properties": { }
}