在 Azure ARM 模板中使用字符串连接变量
Concat variable with string in Azure ARM Template
我现在真的很沮丧,但我就是无法让它发挥作用。对 ARM 模板有点陌生,很抱歉我的无知。
我正在尝试将 parameters.json 与 New-AzResourceGroupDeployment 一起使用,但我想在 VMName 中动态提供它。
我正在尝试将其用于 NSG 名称:
"value": "[concat(variables('vmName'),'-nsg')]"
但是我得到一个错误:
New-AzResourceGroupDeployment: 6:39:21 AM - Error:
Code=InvalidResourceName; Message=Resource name
[concat(variables('vmName'),'-nsg')] 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 '.', '-', ''.
我错过了什么?
你在哪里使用Concat函数?因为ARM模板函数只有ARM模板本身才有,.parameters.json文件里没有。
作为回复编辑:
这实际上取决于用例,但如果给定 ARM 模板的 'nsg' 值不变,我会在主 ARM 模板中执行类似的操作。如果确实如此,则定义第二个参数 'vmsuffix' 并将两个参数连接到完整的 VM 名称中。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VmName": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"FullVmName": "[concat(parameters('VmName'), 'nsg')]"
},
"resources": [
{
...
## Use the [variables('FullVmName') somewhere here
}
]
}
我现在真的很沮丧,但我就是无法让它发挥作用。对 ARM 模板有点陌生,很抱歉我的无知。
我正在尝试将 parameters.json 与 New-AzResourceGroupDeployment 一起使用,但我想在 VMName 中动态提供它。
我正在尝试将其用于 NSG 名称:
"value": "[concat(variables('vmName'),'-nsg')]"
但是我得到一个错误:
New-AzResourceGroupDeployment: 6:39:21 AM - Error: Code=InvalidResourceName; Message=Resource name [concat(variables('vmName'),'-nsg')] 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 '.', '-', ''.
我错过了什么?
你在哪里使用Concat函数?因为ARM模板函数只有ARM模板本身才有,.parameters.json文件里没有。
作为回复编辑:
这实际上取决于用例,但如果给定 ARM 模板的 'nsg' 值不变,我会在主 ARM 模板中执行类似的操作。如果确实如此,则定义第二个参数 'vmsuffix' 并将两个参数连接到完整的 VM 名称中。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"VmName": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
"FullVmName": "[concat(parameters('VmName'), 'nsg')]"
},
"resources": [
{
...
## Use the [variables('FullVmName') somewhere here
}
]
}