Azure ARM模板部署

时间:2018-09-06 10:54:51

标签: azure arm-template

我正在尝试通过Azure ARM模板为VM创建NIC卡。但是我的脚本还创建了到应用程序网关的concats NIC。但是到目前为止,我仅创建VM和NIC。是否有条件跳过应用程序网关和NIC的串联。以下是NIC创建模板:

{
    "comments": "NIC_Creation",
    "tags": {
        "owner": "[parameters('owner')]"
    },
    "condition": "[equals(parameters('CreateVM'), 'yes')]",
    "dependsOn": [
        // "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]",
        // "[resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]",
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name'))]",
        "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('NSG_Name'))]",
        "[resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name'))]"

    ],
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[parameters('NIC_Name')]",
    "apiVersion": "2018-02-01",
    "location": "[parameters('myvmlocation')]",
    "scale": null,
    "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "e319fe3b-4162-4501-81e7-b657be52f411",
        "ipConfigurations": [
            {
                "name": "ipconfig1",
                "etag": "W/\"a9185125-7a6e-4811-ae29-4afe520e7c4f\"",
                "properties": {
                    "provisioningState": "Succeeded",
                    "privateIPAddress": "192.168.1.4",//192.168.1.4   //172.19.0.5
                    "privateIPAllocationMethod": "Dynamic",
                    "publicIPAddress": {
                        "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('VM_PublicIP_Name'))]"
                    },
                    "subnet": {
                        "id": "[concat(resourceId('Microsoft.Network/virtualNetworks', parameters('VNET_Name')), '/subnets/',parameters('subnetname'))]"
                    },
                    "primary": true,
                    "privateIPAddressVersion": "IPv4",
                     "applicationGatewayBackendAddressPools": [

                        {
                            "condition": "[equals(parameters('CreateAppgateway'), 'yes')]",
                            "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/sxBackendPool')]"
                        },
                        {
                            "condition": "[equals(parameters('CreateAppgateway'), 'yes')]",
                            "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/nxBackendPool')]"
                        }
                    ]
                }
            }
        ],
        "dnsSettings": {
            "dnsServers": [],
            "appliedDnsServers": []
        },
        "macAddress": "00-0D-3A-1F-51-61",
        "enableAcceleratedNetworking": false,
        "enableIPForwarding": false,
        "networkSecurityGroup": {
            "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('NSG_Name'))]"
        },
        "primary": true
    }
},

我已在applicationGatewayBackendAddressPools内添加了一个条件,但它不起作用。有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

否,您不能对单个属性设置条件。您可以做的是将if()函数与变量和json()函数一起使用以计算所需的结果

"applicationGatewayBackendAddressPools": "[if(equals(parameters('CreateAppgateway'), 'yes'), variables('applicationGateways'), json('null'))]"

答案 1 :(得分:0)

首先,所有功劳归功于https://stackoverflow.com/users/6067741/4c74356b41(4c74356b41),他帮助解决了这一问题。感谢您的帮助。

我使用了IF函数,并实现如下所示。奏效了!

"variables": {
    "AssociateNIC":  
    [{
        "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/sxBackendPool')]"
    },
    {
        "id": "[concat(resourceId('Microsoft.Network/applicationGateways', parameters('AppGateWay_Name')), '/backendAddressPools/nxBackendPool')]"
    }]

},

"applicationGatewayBackendAddressPools": "[if(equals(parameters('CreateAppgateway'), 'yes'), variables('AssociateNIC'), json('null'))]"