0

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

Eddie Ace
  • 1
  • 1

1 Answers1

0

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

Jahnavi
  • 3,076
  • 1
  • 3
  • 10
  • Hi Jahnavi and thanks a million for your help! In my code, the Automation account variable is a child resource to the automation account and therefore, the parent name and type should not be in the name/type in the child resource. I tried also to create the automation account variable as an child resource outside of the parent and then using the two segments automationaccount/variables in the name and type and got the same error. I tried your code aswell and made some tweak to define parameters etc and it didn't work with the AAvariable! However, it worked when i removed the AAvariable. – Eddie Ace Jun 22 '23 at 07:24
  • What is the exact issue you are facing now? – Jahnavi Jun 22 '23 at 07:30
  • Hi again. The "value" under properties of the automation account variable only accepts integers for me. So now i know exactly what the problem is. I'll investigate further why that is. Thanks for your help! – Eddie Ace Jun 22 '23 at 10:04
  • okay, now it's solved. I simply had to write "value": "'varValue'".That is, 'varValue' inside the "". Thanks for the help! – Eddie Ace Jun 22 '23 at 12:51