[英]Azure ARM Template Parameter Based on Input Parameter
Given a template.json with: 给定一个template.json与:
"parameters": {
"virtualMachineName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
}
}
How can I set the networkInterfaceName based upon the input of virtualMachineName? 如何根据virtualMachineName的输入设置networkInterfaceName?
For example: 例如:
New-AzureRmResourceGroupDeployment -Name MyDeployment -TemplateFile .\template.json -TemplateParameterFile .\parameters.json
will prompt for VirtualMachineName and if 'test-vm' is entered, we would like the networkInterfaceName to default to 'test-vm-nic'. 将提示您输入VirtualMachineName,如果输入了“ test-vm”,我们希望networkInterfaceName默认为“ test-vm-nic”。
We have tried adding this parameters.json: 我们尝试添加以下parameter.json:
"networkInterfaceName": {
"value": "[concat(parameters('virtualMachineName'),'_nic')]"
},
but receive the error: 但收到错误:
Error: Code=InvalidResourceName; Message=Resource name
[concat(parameters('virtualMachineName'),'_nic')] is invalid. The
name can be up to 80 characters long. It must begin with a word character,
and it must end with a word character or with '_'. The name may contain word
characters or '.', '-', '_'.
You could add the NIC name under variables in the main template, instead of under parameters. 您可以在主模板的变量下而不是参数下添加NIC名称。 Your parameters section would then only hold the 'virtualMachineName' parameter: 然后,您的parameters部分将仅包含'virtualMachineName'参数:
"parameters": {
"virtualMachineName": {
"type": "string"
}
},
"variables": {
"networkInterfaceName": "[concat(parameters('virtualMachineName'),'_nic')]"
},
"resources":{
...
}
In the resource definition, you would define the nic name as 在资源定义中,应将nic名称定义为
variables('networkInterfaceName')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.