Ошибка получения вложенного шаблона в шаблоне Azure Arm - PullRequest
0 голосов
/ 29 января 2019

Я столкнулся с проблемой в шаблоне.Я хочу связать другой шаблон в основном шаблоне, но я столкнулся с проблемой в строке 69, я изменил все, но все еще получаю ошибку.Проверьте ниже код:

{
    "$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": {},
    "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')]"
                    }
                }
            ]
        }     
    "resources": [
            {
                "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",
                        "variables": {
                            "virtualNetworkName": "virtualNetwork",
                            "subnetName": "subnet",
                            "loadBalancerName": "loadBalancer",
                            "nicName": "networkInterface",
                            "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
                        },
                        "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"
                                        }
                                    ]
                                }
                            }
                        ]
                    }

1 Ответ

0 голосов
/ 29 января 2019

это пример, который может работать:

{
    "$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"
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        }
    ]
}

Я не уверен в использовании переменных во вложенном шаблоне, объявленном во вложенном шаблоне, которые могут не работать.Я бы предложил перенести их в родительский шаблон или (лучше) использовать связанный шаблон (как в примере выше).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...