парсинг переменных в файле шаблона Azure ARM - PullRequest
0 голосов
/ 11 марта 2020

Я пишу Azure шаблон ARM для развертывания VNET. Поэтому у меня есть файл развертывания "VNET. json и файл параметров" VNET .parameter. json.

Теперь я хочу передать ТОЛЬКО в параметре File переменную, но всегда получил ошибку:

'The template variable 'IP' is not found. Please see https://aka.ms/arm-template/#variables for usage details.

или не разрешено использовать переменную в параметре?

Вот мой файл json.

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "variables": {
        "IP": "172.37.0.0/24"
    },
    "parameters": {
        "VNetSettings":{
            "value":{
                "name":"ManagementNW",
                "addressPrefixes": [
                    {
                        "name": "VPN",
                        "addressPrefix": "192.168.0.0/16"
                    },
                    {
                        "name": "Control",
                        "addressPrefix": "172.37.0.0/16"
                    },
                    {
                        "name": "Service",
                        "addressPrefix": "172.36.0.0/16"
                    },
                    {
                        "name": "DMZ",
                        "addressPrefix": "172.35.4.0/24"
                    }
                ],
                "subnets":[
                    {
                        "name": "VPN-subnet",
                        "addressPrefix": "192.168.1.0/24"
                    },
                    {
                        "name": "Control-subnet",
                        "addressPrefix": "172.37.0.0/24"
                    },
                    {
                        "name": "Service-subnet",
                        "addressPrefix": "172.36.0.0/24"
                    },
                    {
                        "name": "DMZ-subnet",
                        "addressPrefix": "172.35.4.0/24"
                    },
                    {
                        "name": "Gateway-subnet",
                        "addressPrefix": "192.168.255.0/24"
                    },
                    {
                        "name":"AzureFirewall-subnet",
                        "addressPrefix":"192.168.254.0/24"
                    }
                ]
            }
        },
        "Control-NSG-settings": {
            "value": {
                "securityRules": [
                    {
                        "direction": "Inbound",
                        "name": "VPNGW_to_Tableau_all",
                        "sourceAddressPrefix": "192.168.255.0/24",
                        "sourcePortRange": "*",
                        "destinationAddressPrefix": "172.37.0.41",
                        "destinationPortRange": "*",
                        "protocol": "*",
                        "access": "Allow",
                        "priority": 101,
                        "description": "allow RDP connections"
                    },
                    {
                        "direction": "Inbound",
                        "name": "VPNGW_to_Control_all",
                        "sourceAddressPrefix": "192.168.255.0/24",
                        "sourcePortRange": "*",
                        "destinationAddressPrefix": "[variables('IP')]",
                        "destinationPortRange": "*",
                        "protocol": "*",
                        "access": "deny",
                        "priority": 102,
                        "description": "deny"
                    },

KR Marvin

1 Ответ

1 голос
/ 12 марта 2020

В шаблоне вы ссылаетесь на значение параметра, используя функцию переменных .

В файле json шаблона ARM вы используете переменные, чтобы упростить ваш шаблон. Вместо того, чтобы повторять сложные выражения по всему шаблону, вы определяете переменную, которая содержит сложное выражение. Однако, если вы используете только один раз, вам не нужно использовать переменные.

Кроме того, как сказал usrone, ваш шаблон выглядит подозрительно. Обычный шаблон такой, на который вы могли бы ссылаться.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "",
  "apiProfile": "",
  "parameters": {  },
  "variables": {  },
  "functions": [  ],
  "resources": [  ],
  "outputs": {  }
}
...