我正在通过ARM模板创建应用程序网关,参考-Create Application Gateway v2 我想从上述模板中为应用程序网关创建多个属性实例,即“ backendAddressPools”,“ backendHttpSettingsCollection”等。无法通过“复制”创建多个实例。
尝试按照-multipleinstances中提供的示例实施,显示在Azure DevOps管道中执行时的以下错误。
无法处理资源的模板语言表达式 '/subscriptions/XXXXXX/resourceGroups/rsgAppGw/providers/Microsoft.Network/applicationGateways/appGwV2' 在“ 1”行和“ 2537”列。 '模板函数'copyIndex'是 在此位置不期望。该功能只能在 指定了副本的资源。
azuredeploy.json
iptables:
"{{ item.key }}": lo
with_items:
- { key: in_interface }
- { key: out_interface }
azuredeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetworkName": {
"type": "string",
"defaultValue": "Application-Vnet",
"metadata": {
"description": "Virtual Network name"
}
},
"vnetAddressPrefix": {
"type": "string",
"defaultValue": "10.0.0.0/16",
"metadata": {
"description": "Virtual Network address range"
}
},
"subnetName": {
"type": "string",
"defaultValue": "ApplicationGatewaySubnet",
"metadata": {
"description": "Name of the subnet"
}
},
"subnetPrefix": {
"type": "string",
"defaultValue": "10.0.0.0/24",
"metadata": {
"description": "Subnet address range"
}
},
"applicationGatewayName": {
"type": "string",
"defaultValue": "applicationGatewayV2",
"metadata": {
"description": "Application Gateway name"
}
},
"minCapacity": {
"type": "int",
"defaultValue": 2,
"metadata": {
"description": "Minimum instance count for Application Gateway"
}
},
"frontendPort": {
"type": "int",
"defaultValue": 80,
"metadata": {
"description": "Application Gateway Frontend port"
}
},
"backendPort": {
"type": "int",
"defaultValue": 80,
"metadata": {
"description": "Application gateway Backend port"
}
},
"backendAddressPools": {
"type": "array",
"defaultValue": "",
"metadata": {
"description": ""
}
},
"backendIPAddresses": {
"type": "array",
"metadata": {
"description": "Back end pool ip addresses"
}
},
"cookieBasedAffinity": {
"type": "string",
"allowedValues": ["Enabled", "Disabled"],
"defaultValue": "Disabled",
"metadata": {
"description": "Cookie based affinity"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"appGwPublicIpName": "[concat(parameters('applicationGatewayName'), '-pip')]",
"appGwPublicIPRef": "[resourceId('Microsoft.Network/publicIPAddresses',variables('appGwPublicIpName'))]",
"appGwSize": "Standard_v2",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
},
"resources": [
{
"apiVersion": "2018-08-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": ["[parameters('vnetAddressPrefix')]"]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "2018-08-01",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('appGwPublicIpName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAllocationMethod": "Static"
}
},
{
"apiVersion": "2018-08-01",
"name": "[parameters('applicationGatewayName')]",
"type": "Microsoft.Network/applicationGateways",
"location": "[parameters('location')]",
"dependsOn": [
"[variables('appGwPublicIPRef')]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]"
],
"properties": {
"sku": {
"name": "[variables('appGwSize')]",
"tier": "Standard_v2"
},
"autoscaleConfiguration": {
"minCapacity": "[parameters('minCapacity')]"
},
"gatewayIPConfigurations": [
{
"name": "appGatewayIpConfig",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
],
"frontendIPConfigurations": [
{
"name": "appGatewayFrontendIP",
"properties": {
"PublicIPAddress": {
"id": "[variables('appGwPublicIpRef')]"
}
}
}
],
"copy": [
{
"name": "frontendPorts",
"count": 1,
"input": {
"name": "appGatewayFrontendPort",
"properties": {
"Port": "[parameters('frontendPort')]"
}
}
},
{
"name": "backendAddressPools",
"count": "[length(parameters('backendAddressPools'))]",
"input": {
"name": "[parameters('backendAddressPools')[copyIndex('backendAddressPools')].name]"
},
"copy":{
"name":"copybackendIPAddresses",
"count":"[length(parameters('backendIPAddresses'))]",
"properties":{
"IpAddress":"[parameters('backendIPAddresses')[copyIndex('copybackendIPAddresses')].IpAddress]",
"fqdn":"[parameters('backendIPAddresses')[copyIndex('copybackendIPAddresses')].fqdn]"
}
}
},
{
"name": "backendHttpSettingsCollection",
"count": 1,
"input": {
"name": "appGatewayBackendHttpSettings",
"properties": {
"Port": "[parameters('backendPort')]",
"Protocol": "Http",
"CookieBasedAffinity": "[parameters('cookieBasedAffinity')]"
}
}
},
{
"name": "httpListeners",
"count": 1,
"input": {
"name": "appGatewayHttpListener",
"properties": {
"FrontendIpConfiguration": {
"Id": "[resourceId('Microsoft.Network/applicationGateways/frontendIPConfigurations', parameters('applicationGatewayName'), 'appGatewayFrontendIP')]"
},
"FrontendPort": {
"Id": "[resourceId('Microsoft.Network/applicationGateways/frontendPorts', parameters('applicationGatewayName'), 'appGatewayFrontendPort')]"
},
"Protocol": "Http"
}
}
},
{
"name": "requestRoutingRules",
"count": 1,
"input": {
"name": "rule1",
"properties": {
"RuleType": "Basic",
"httpListener": {
"id": "[resourceId('Microsoft.Network/applicationGateways/httpListeners', parameters('applicationGatewayName'), 'appGatewayHttpListener')]"
},
"backendAddressPool": {
"id": "[resourceId('Microsoft.Network/applicationGateways/backendAddressPools', parameters('applicationGatewayName'), 'appGatewayBackendPool')]"
},
"backendHttpSettings": {
"id": "[resourceId('Microsoft.Network/applicationGateways/backendHttpSettingsCollection', parameters('applicationGatewayName'), 'appGatewayBackendHttpSettings')]"
}
}
}
}
]
}
}
]
}
要创建为应用程序网关提供的属性的多个实例。
答案 0 :(得分:1)
感谢@ 4c74356b41 我在我的环境中对其进行了测试,并且可以进行较小的更改。
请参阅下文,我在资源部分中使用了它:
"copy": [
{
"name": "backendAddressPools",
"count": "[length(parameters('backendAddressPoolsarray'))]",
"input": {
"name": "[parameters('backendAddressPoolsarray')[copyIndex('backendAddressPools')].name]",
"properties": {
"BackendAddresses": "[parameters('backendAddressPoolsarray')[copyIndex('backendAddressPools')].backendIPAddresses]"
}
}
}
],
这是参数文件
"backendAddressPoolsArray": {
"value": [
{
"Name": "BP1",
"backendIPAddresses": [
{
"IpAddress": "10.0.0.4"
},
{
"IpAddress": "10.0.0.5"
}
]
},
{
"Name": "BP2",
"backendIPAddresses": [
{
"IpAddress": "10.0.0.6"
},
{
"IpAddress": "10.0.0.7"
}
]
},
也不需要使用对象,数组很好
答案 1 :(得分:0)
这是我一直在做的一个例子:
{
"apiVersion": "2018-04-01",
"name": "[deployment().name]",
"type": "Microsoft.Network/applicationGateways",
"location": "[resourceGroup().location]",
"properties": {
"copy": [
{
"name": "backendAddressPools",
"count": "[length(parameters('backendAddressPools'))]",
"input": {
"name": "[parameters('backendAddressPools')[copyIndex('backendAddressPools')].name]",
"properties": "[parameters('backendIPAddresses')[copyIndex('backendAddressPools')]]"
}
}
]
}
}
那只是您需要适应您的需求的示例,但是它展示了这个想法,您需要使用properties
属性(doh)内的复制功能并定义要获取的内容。我已经为您定义了backendAddressPools
,它应该根据我的想法或多或少地起作用(我可能是错的,因此可能需要在这里稍作修改)。