【问题标题】:Azure Resource Manager: How to specify optional parameters in linked templatesAzure 资源管理器:如何在链接模板中指定可选参数
【发布时间】:2019-04-26 13:54:04
【问题描述】:

我正在使用链接模板来部署公共资源。在这种情况下,我正在部署一个VM,它定义了一个可选参数AdminPassword,仅在某些情况下需要(即当参数PasswordAuthenticationDisabled设置为false时):

"parameters": {
    "AdminPassword": {
        "type": "securestring",
        "defaultValue": null,
        "metadata": {
            "description": "Password when password-based authentication isn't disabled"
        }
    },
    "PasswordAuthenticationDisabled": {
        "type": "bool",
        "defaultValue": "true",
        "metadata": {
            "description": "Should password-based authentication thorugh SSH be disabled"
        }
    }
}

我引用的链接模板如下:

{
    "type": "Microsoft.Resources/deployments",
    "name": "[variables('nameDeploymentVmAttacker1')]",
    "apiVersion": "2017-05-10",
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "[concat(variables('urlTemplates'), '/vm/ubuntu-18.04.json')]"
        },
        "parameters": {
            "Name": {
                "value": "[variables('nameVmAttacker1')]"
            },
            "Region": {
                "value": "[resourceGroup().location]"
            },
            "AdminUsername": {
                "value": "[parameters('AdminUsername')]"
            },
            "AdminSshKey": {
                "value": "[parameters('AdminSshKey')]"
            },
            "VmSize": {
                "value": "[parameters('VmSize')]"
            },
            "VnetName": {
                "value": "[variables('nameVnet')]"
            },
            "PasswordAuthenticationDisabled": {
                "value": true
            }
        }
    }
}

没有指定可选参数。这导致 ARM 抱怨缺少参数:Deployment template validation failed: 'The value for the template parameter 'AdminPassword' at line '25' and column '26' is not provided. Please see https://aka.ms/arm-deploy/#parameter-file for usage details.

如何告诉调用模板尊重参数的可选性并使用默认值?

【问题讨论】:

    标签: azure azure-resource-manager arm-template


    【解决方案1】:

    将 defaultValue 设置为 null 以外的值,例如一个空字符串。对于这种情况,你也可以这样做:https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      相关资源
      最近更新 更多