我正在为NSG准备ARM模板。以下是我的模板文件
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"nsgName": {
"type": "string"
},
"securityRulesArray": {
"type": "array",
"metadata": {
"description": "All required rules (name, description, protocol) in an array"
}
}
},
"variables": {},
"resources": [
{
"comments": "",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[parameters('nsgName')]",
"apiVersion": "2018-02-01",
"location": "westus",
"properties": {
"copy": [
{
"name": "securityRules",
"count": "[length(parameters('securityRulesArray'))]",
"input": {
"name": "[parameters('securityRulesArray')[copyIndex('securityRules')].ruleName]",
"properties": {
"description": "[parameters('securityRulesArray')[copyIndex('securityRules')].description]",
"protocol": "[parameters('securityRulesArray')[copyIndex('securityRules')].protocol]",
"sourcePortRange": "[parameters('securityRulesArray')[copyIndex('securityRules')].sourcePortRange]",
"destinationAddressPrefix": "[parameters('securityRulesArray')[copyIndex('securityRules')].destinationAddressPrefix]",
"access": "[parameters('securityRulesArray')[copyIndex('securityRules')].access]",
"priority": "[parameters('securityRulesArray')[copyIndex('securityRules')].priority]",
"direction": "[parameters('securityRulesArray')[copyIndex('securityRules')].direction]",
"sourcePortRanges": "[parameters('securityRulesArray')[copyIndex('securityRules')].sourcePortRanges]",
"destinationPortRanges": "[parameters('securityRulesArray')[copyIndex('securityRules')].destinationPortRanges]",
"sourceAddressPrefixes": "[parameters('securityRulesArray')[copyIndex('securityRules')].sourceAddressPrefixes][copyIndex()]",
"destinationAddressPrefixes": "[parameters('securityRulesArray')[copyIndex('securityRules')].destinationAddressPrefixes[copyIndex()]]",
"destinationPortRange": "[parameters('securityRulesArray')[copyIndex('securityRules')].destinationPortRange]",
"sourceAddressPrefix": "[parameters('securityRulesArray')[copyIndex('securityRules')].sourceAddressPrefix]"
}
}
}
]
},
"dependsOn": []
}
]
}
相同的参数文件
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"nsgName": {
"value": "testnsgsample4"
},
"securityRulesArray": {
"value": [
{
"ruleName": "11.113.218.1-21",
"description": "Allow inbound traffic",
"protocol": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "11.112.34.11",
"access": "Allow",
"priority": "105",
"direction": "Inbound",
"sourcePortRanges": [],
"destinationPortRanges": [
"3389",
"22",
"443",
"135",
"137",
"445",
"389",
"636",
"49152-65535"
],
"sourceAddressPrefixes": [
"11.11.137.72",
"11.11.98.177",
"11.11.99.22",
"11.11.99.22"
],
"destinationAddressPrefixes": [],
"destinationPortRange": null,
"sourceAddressPrefix": null
}
]
}
}
}
当有子数组参数(在我的情况下为destination / sourceportranges和source / destinationaddress前缀)时,我的模板不起作用。我通过在下面手动进行检查,效果很好。我想知道如何通过父数组参数传递子数组参数。谢谢您的帮助。
//"destinationPortRanges": "[parameters('securityRulesArray')[copyIndex('securityRules')].destinationPortRanges]",
"destinationPortRanges": [
"3389",
"22",
"443",
"135",
"137",
"445",
"389",
"636",
"49152-65535"
],
答案 0 :(得分:0)
您正在做的事情没有意义,您应该做的是这样:
{
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[parameters('nsgName')]",
"apiVersion": "2018-02-01",
"location": "westus",
"properties": "[parameters('securityRulesArray')]"
}
我会说这种方法很奇怪。