嵌套模板在Azure Arm模板中出现错误

时间:2019-01-29 11:18:15

标签: azure

我在模板中遇到问题。 我想链接主模板中的另一个模板,但是我在第69行中遇到问题,我改变了所有但仍然出现错误。 检查以下代码:

curl -v http://localhost:8085/geoserver/web
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8085 (#0)
> GET /geoserver/web HTTP/1.1
> Host: localhost:8085
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Set-Cookie: JSESSIONID=node01pdyu4npf3xt6130w8gehjai7t0.node0;Path=/geoserver
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Location: http://localhost:8085/geoserver/web/;jsessionid=node01pdyu4npf3xt6130w8gehjai7t0.node0
< Content-Length: 0
< Server: Jetty(9.4.12.v20180830)
< 
* Connection #0 to host localhost left intact

1 个答案:

答案 0 :(得分:0)

此示例可能有效:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vnetName": {
            "type": "string",
            "defaultValue": "VNet",
            "metadata": {
                "description": "VNet name"
            }
        },
        "vnetAddressPrefix": {
            "type": "string",
            "defaultValue": "10.0.0.0/16",
            "metadata": {
                "description": "Address prefix"
            }
        },
        "subnetPrefix": {
            "type": "string",
            "defaultValue": "10.0.0.0/24",
            "metadata": {
                "description": "Subnet  Prefix"
            }
        },
        "subnetName": {
            "type": "string",
            "defaultValue": "Subnet",
            "metadata": {
                "description": "Subnet  Name"
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "virtualNetworkName": "virtualNetwork",
        "subnetName": "subnet",
        "loadBalancerName": "loadBalancer",
        "nicName": "networkInterface",
        "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
    },
    "resources": [
        {
            "apiVersion": "2018-06-01",
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[parameters('vnetName')]",
            "location": "[parameters('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[parameters('vnetAddressPrefix')]"
                    ]
                }
            },
            "resources": [
                {
                    "apiVersion": "2018-06-01",
                    "type": "subnets",
                    "location": "[parameters('location')]",
                    "name": "[parameters('subnetName')]",
                    "dependsOn": [
                        "[parameters('vnetName')]"
                    ],
                    "properties": {
                        "addressPrefix": "[parameters('subnetPrefix')]"
                    }
                }
            ]
        },
        {
            "apiVersion": "2017-05-10",
            "name": "nestedTemplate",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "resources": [
                        {
                            "apiVersion": "2015-06-15",
                            "type": "Microsoft.Network/virtualNetworks",
                            "name": "[variables('virtualNetworkName')]",
                            "location": "[parameters('location')]",
                            "properties": {
                                "addressSpace": {
                                    "addressPrefixes": [
                                        "[parameters('vnetAddressPrefix')]"
                                    ]
                                },
                                "subnets": [
                                    {
                                        "name": "[variables('subnetName')]",
                                        "properties": {
                                            "addressPrefix": "[parameters('subnetPrefix')]"
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "apiVersion": "2015-06-15",
                            "type": "Microsoft.Network/networkInterfaces",
                            "name": "[variables('nicName')]",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[concat('Microsoft.Network/loadBalancers/', variables('loadBalancerName'))]"
                            ],
                            "properties": {
                                "ipConfigurations": [
                                    {
                                        "name": "ipconfig1",
                                        "properties": {
                                            "privateIPAllocationMethod": "Dynamic",
                                            "subnet": {
                                                "id": "[variables('subnetRef')]"
                                            },
                                            "loadBalancerBackendAddressPools": [
                                                {
                                                    "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')),'/backendAddressPools/loadBalancerBackEnd')]"
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "apiVersion": "2015-06-15",
                            "name": "[variables('loadBalancerName')]",
                            "type": "Microsoft.Network/loadBalancers",
                            "location": "[parameters('location')]",
                            "dependsOn": [
                                "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
                            ],
                            "properties": {
                                "frontendIPConfigurations": [
                                    {
                                        "name": "loadBalancerFrontEnd",
                                        "properties": {
                                            "subnet": {
                                                "id": "[variables('subnetRef')]"
                                            }
                                        }
                                    }
                                ],
                                "backendAddressPools": [
                                    {
                                        "name": "loadBalancerBackEnd"
                                    }
                                ],
                                "loadBalancingRules": [
                                    {
                                        "properties": {
                                            "frontendIPConfiguration": {
                                                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/frontendIpConfigurations/loadBalancerFrontEnd')]"
                                            },
                                            "backendAddressPool": {
                                                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/backendAddressPools/loadBalancerBackEnd')]"
                                            },
                                            "probe": {
                                                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName')), '/probes/lbprobe')]"
                                            },
                                            "protocol": "Tcp",
                                            "frontendPort": 80,
                                            "backendPort": 80,
                                            "idleTimeoutInMinutes": 15
                                        },
                                        "name": "lbrule"
                                    }
                                ],
                                "probes": [
                                    {
                                        "properties": {
                                            "protocol": "Tcp",
                                            "port": 80,
                                            "intervalInSeconds": 15,
                                            "numberOfProbes": 2
                                        },
                                        "name": "lbprobe"
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}

我不确定要在嵌套模板中声明的嵌套模板中使用变量,但这可能不起作用。我建议将它们移到父模板或(最好)使用链接模板(如上例所示)。