Eddie Ace
Eddie Ace

Reputation: 1

Error deploying an Azure Automation Account variable using an ARM template

I'm deploying Automation Account resources using ARM and when i try to add a automation account variable (under "resources") i get the error message "Invalid JSON - Kindly check the value of the variable."

The code part is this and it works fine without the automation account variable:

{

"condition":"[parameters('deploy.AUTOMATION')]",
"type":"Microsoft.Automation/automationAccounts",
"apiVersion":"2021-06-22",
"name":"[variables('automationaccount').accountName]",
"location":"[variables('automationaccount').location]",
"dependsOn":[
    "[variables('automationaccount').operationalInsightsWorkspaceName]"
],
"identity":{
    "type":"SystemAssigned"
},
"properties":{
    "sku":{
        "name":"[variables('automationaccount').skuName]"
    },
    "disableLocalAuth":true,
    "publicNetworkAccess":"[variables('automationaccount').publicNetworkAccess]"
},
"resources":[
    {
        "type":"variables",
        "apiVersion":"2020-01-13-preview",
        "name":"DummyName",
        "dependsOn":[
            "[variables('automationaccount').accountName]"
        ],
        "properties":{
            "description":"Dummydesc",
            "isEncrypted":false,
            "value":"DummyValue"
        }
    }
],
"tags":"[parameters('tags')]",
"comments":""

}

Any ideas what's wrong?

Documentation for Microsoft.Automation automationAccounts/variables https://learn.microsoft.com/en-us/azure/templates/microsoft.automation/automationaccounts/variables?pivots=deployment-language-arm-template

I'm expecting the automation account variable to be created. I've tried to deploy the stated code in Azure Cloud shell (as part of a longer script defining parameters and variables etc).

I've also tried to write the automation account variable as an outside parent resource and get the same error.

BR Edvin

Upvotes: 0

Views: 333

Answers (1)

Jahnavi
Jahnavi

Reputation: 7898

According to the MSDoc, you need to provide the whole resource type when defining the child resource outside of the parent. If you want to pass automation variables, you must pass the variable name along with the two segments as automationaccount/variables.

I tried deploying an automation account with the variables as follows and was able to ran it successfully.

Refer this template from MSDoc regarding automation account creation.

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
"metadata": {
"description": "Workspace"
}
},
"sku": {
"type": "string",
"defaultValue": "pergb2018",
"allowedValues": [
"pergb2018",
"Free"
],
},
"dataRetention": {
"type": "int",
"defaultValue": 30
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": ""
}
},
"automationAccountName": {
"type": "string"
},
"samplePowerShellRunbookName": {
"type": "String",
"defaultValue": "Script"
},
"samplePowerShellRunbookDescription": {
"type": "String",
"defaultValue": ""
}
}
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-08-01",
"name": "[parameters('workspace')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "[parameters('sku')]"
},
"retentionInDays": "[parameters('dataRetention')]",
"features": {
"searchVersion": 1,
"legacy": 0
    }
  }
},
{
"type": "Microsoft.Automation/automationAccounts",
"apiVersion": "2020-01-13-preview",
"name": "[parameters('automationAccountName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[parameters('workspace')]"
],
"identity": {
"type": "SystemAssigned"
},
"properties": {
"sku": {
"name": "Basic"
}
},
"resources": [
{
"type": "runbooks",
"apiVersion": "2020-01-13-preview",
"name": "[parameters('samplePowerShellRunbookName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[parameters('automationAccountName')]"
],
"properties": {
"runbookType": "PowerShell",
"logProgress": "false",
"logVerbose": "false",
"description": "[parameters('samplePowerShellRunbookDescription')]"
       }
     }
   ]
},
{
"type": "Microsoft.OperationalInsights/workspaces/linkedServices",
"apiVersion": "2020-08-01",
"name": "[concat(parameters('workspace'), '/' , 'Automation')]",
"location": "[parameters('location')]",
"dependsOn": [
"[parameters('workspace')]",
"[parameters('automationAccountName')]"
],
"properties": {
"resourceId": "[resourceId('Microsoft.Automation/automationAccounts', parameters('automationAccountName'))]"
}
},
{
"type": "Microsoft.Automation/automationAccounts/variable",
"apiVersion": "2022-08-08",
"name": "autosili/myvariable",
"dependsOn":[
"[parameters('automationAccountName')]"
],
"properties": {
"description": "xxxx",
"value": "varValue"
}
}
]
}

Using below PowerShell command, I've deployed it to the Azure services.

New-AzResourceGroupDeployment -Name <templatename> -ResourceGroupName <ResourceGroup> -TemplateFile <jsonfilepath>

enter image description here

enter image description here

Upvotes: 0

Related Questions