Azure资源管理器:如何在链接的模板中指定可选参数 [英] Azure Resource Manager: How to specify optional parameters in linked templates

查看:62
本文介绍了Azure资源管理器:如何在链接的模板中指定可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making use of linked templates to deploy common resources. In this case I'm deploying a VM which has an optional parameter defined AdminPassword that is only required in certain scenarios (namely when the parameter PasswordAuthenticationDisabled is set to 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"
        }
    }
}

我引用的链接模板如下:

I'm referencing the linked template as follows:

{
    "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.

Without the optional parameter specified. This leads to ARM complaining about the missing parameter: 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.

如何告诉调用模板遵守参数的可选性,而仅使用默认值?

How can I tell the calling template to honor the optionality of the parameter and just go with the default value?

推荐答案

将defaultValue设置为非null的值,例如一个空字符串.对于这种情况,您还可以执行以下操作: https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36

Set the defaultValue to something other than null, e.g. an empty string. For this scenario, you can also do something like this: https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36

这篇关于Azure资源管理器:如何在链接的模板中指定可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆