我有一個包含2級嵌套模板的父級模板,azuredeploy.json-> vmReferenceTemplate.json-> datadiskreference.json當我將所需值從第二級傳遞到第三級時,它將部署很好,但是當從第一級到第三級嵌套模板傳遞完全相同的值時,它不起作用。我想從azuredeploy.json numDataDisks值datadiskreference.json我有一個非常複雜的模板,爲了它的工作,我必須傳遞第一級的值。這是條紋的版本,工作。 azuredeploy.json:Azure RM模板。將複數值傳遞到第三級嵌套模板
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters": {
,,,
"numberOfVMs": {
"type": "int",
"defaultValue": 8,
},
"numberOfDataDisks": {
"type": "array",
"defaultValue": [
2,
1,
3,
1,
1,
1,
1,
1
]
},
...
},
"resources": [
{
"name": "[concat(parameters('vmName'), copyIndex(1),'-','reference')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"copy": {
"name": "vmReferenceTemplateLoop",
"count": "[parameters('numberOfVMs')]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('vmReferenceTemplateTemplateFolder'), '/', variables('vmReferenceTemplateTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"numDataDisks": {
"value": "[parameters('numberOfVMs')]"
}
}
}
}
],
...
vmReferenceTemplate.json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters": {
...
"numberOfVMs": {
"type": "int",
"defaultValue": 2
},
"numberOfDataDisks": {
"type": "array",
"defaultValue": [
2,
1,
3,
1,
1,
1,
1,
1
]
},
...
},
"resources":
{
"apiVersion": "2016-09-01",
"name": "[parameters('dataDisksReferenceTemplateName')]",
"type": "Microsoft.Resources/deployments",
"copy": {
"name": "dataDiskReferenceLoop",
"count": "[parameters('copyNestedReference')]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('dataDiskReferenceTemplateUri')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": {
"value": "[parameters('dataDisksVMnameReference')]"
},
"storageAccountName": {
"value": "[variables('var_storageAccountName')]"
},
"numDataDisks": {
"value": "[parameters('numberOfDataDisks')[copyIndex()]]"
},
"sizeOfEachDataDiskInGB": {
"value": "[variables('sizeOfEachDataDiskInGB')]"
}
}
}
}
],
...
這是我怎樣,我想從1級到3級傳遞值,但它失敗,出現錯誤"Deployment template validation failed: 'The provided value for the template parameter 'numDataDisks' at line '36' and column '22' is not valid.'."
azuredeploy以.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters": {
,,,
"numberOfVMs": {
"type": "int",
"defaultValue": 8,
},
"numberOfDataDisks": {
"type": "array",
"defaultValue": [
2,
1,
3,
1,
1,
1,
1,
1
]
},
...
},
"resources": [
{
"name": "[concat(parameters('vmName'), copyIndex(1),'-','reference')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"copy": {
"name": "vmReferenceTemplateLoop",
"count": "[parameters('numberOfVMs')]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('vmReferenceTemplateTemplateFolder'), '/', variables('vmReferenceTemplateTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"numDataDisks": {
"value": "[parameters('numberOfDataDisks')[copyIndex()]]"
}
}
}
}
]
...
vmReferenceTemplate.json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"parameters": {
,,,
"numberOfVMs": {
"type": "int",
"defaultValue": 2,
},
"numberOfDataDisks": {
"type": "array",
"defaultValue": [
2,
1,
3,
1,
1,
1,
1,
1
]
},
...
},
"resources": [
{
"apiVersion": "2016-09-01",
"name": "[parameters('dataDisksReferenceTemplateName')]",
"type": "Microsoft.Resources/deployments",
"copy": {
"name": "dataDiskReferenceLoop",
"count": "[parameters('copyNestedReference')]"
},
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('dataDiskReferenceTemplateUri')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"vmName": {
"value": "[parameters('dataDisksVMnameReference')]"
},
"storageAccountName": {
"value": "[variables('var_storageAccountName')]"
},
"numDataDisks": {
"value": "[parameters('numDataDisks')]"
},
"sizeOfEachDataDiskInGB": {
"value": "[variables('sizeOfEachDataDiskInGB')]"
}
}
}
}
]
...
你是說你正在傳遞值1> 2> 3,它不能正確地從父母傳播給孩子的孩子?另外,MS建議使用2級模板;)所以你認爲1> 3,輸出3到2?這樣該模板只有2個級別? – 4c74356b41
是1> 2> 3未通過。我擔心2級別不適合我,因爲我將密鑰庫傳遞給了複製虛擬機(只能在複製虛擬機時使用嵌套模板完成),並將可變數量的數據磁盤傳遞給該副本虛擬機(只能是如果是複製虛擬機,也使用嵌套模板完成)。 – Max
我現在沒時間了,但明天我會回到這裏,告訴你我的意思。 – 4c74356b41