使用ARM模板部署Azure自动化帐户变量时出错

uyto3xhc  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(90)

我正在使用ARM部署自动化帐户资源,当我尝试添加自动化帐户变量(在“资源”下)时,我收到错误消息“无效JSON -请检查变量的值”。
代码部分是这样的,它在没有自动化帐户变量的情况下工作正常:
{

"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":""

}
有什么问题吗?
Microsoft文档。自动化自动化帐户/变量https://learn.microsoft.com/en-us/azure/templates/microsoft.automation/automationaccounts/variables?pivots=deployment-language-arm-template
我希望创建自动化帐户变量。我尝试在Azure Cloud shell中部署所述代码(作为定义参数和变量等的较长脚本的一部分)。
我还尝试将自动化帐户变量作为外部父资源编写,但得到了相同的错误。
BR Edvin

62lalag4

62lalag41#

根据MSDoc,在父资源之外定义子资源时,需要提供整个资源类型。如果要传递自动化变量,则必须将变量名沿着两个段作为automationaccount/variables传递。
我尝试使用以下变量部署一个自动化帐户,并能够成功运行它。
请参考MSDoc中有关自动创建帐户的模板。

{
"$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"
}
}
]
}

使用下面的PowerShell命令,我已经将其部署到Azure服务。

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

相关问题