给出template.json:
"parameters": {
"virtualMachineName": {
"type": "string"
},
"networkInterfaceName": {
"type": "string"
}
}
如何根据virtualMachineName的输入设置networkInterfaceName?
例如:
New-AzureRmResourceGroupDeployment -Name MyDeployment -TemplateFile .\template.json -TemplateParameterFile .\parameters.json
会提示输入VirtualMachineName,如果' test-vm'输入后,我们希望networkInterfaceName默认为' test-vm-nic'。
我们已尝试添加此参数.json:
"networkInterfaceName": {
"value": "[concat(parameters('virtualMachineName'),'_nic')]"
},
但收到错误:
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 '.', '-', '_'.
答案 0 :(得分:1)
您可以在主模板中的变量下添加NIC名称,而不是在参数下添加。然后,您的参数部分将仅保存'virtualMachineName'参数:
"parameters": {
"virtualMachineName": {
"type": "string"
}
},
"variables": {
"networkInterfaceName": "[concat(parameters('virtualMachineName'),'_nic')]"
},
"resources":{
...
}
在资源定义中,您将nic名称定义为
variables('networkInterfaceName')