Как распечатать выходные данные связанного шаблона с помощью шаблона ARM в Azure

Я использую основной шаблон и связанный шаблон для развертывания. Я хочу распечатать вывод связанного шаблона после развертывания.

Когда я развертываю шаблон ниже. Я получаю ошибку ниже,

Выходные данные шаблона «vmpublicIPName» недействительны: свойство языкового выражения «publicIPName» не существует, доступные свойства: «» .. (Код: DeploymentOutputEvaluationFailed)

  1. Как я могу распечатать вывод переменных, присутствующих в связанном шаблоне?
  2. Есть ли способ распечатать все значения параметров развертывания связанного шаблона в основном шаблоне?

storage.json

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "type": "string"
        },
        "storageAccountType": {
            "type": "string",
            "defaultValue": "Standard_LRS"
        }
    },
    "variables": {
        "location": "[resourceGroup().location]",
        "resourceGroupName": "[resourceGroup().name]",
        "subscriptionId": "[subscription().subscriptionId]"
    },
    "resources": [
        {
            "name": "[concat(parameters('storageAccountName'), '1rmtest')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2015-06-15",
            "location": "[variables('location')]",
            "properties": {
                "accountType": "[parameters('storageAccountType')]"
            },
            "tags": {
                "BuildName": "StorageARM"
            }
        },
        { 
            "apiVersion": "2017-03-01", 
            "name": "TestTemplate", 
            "type": "Microsoft.Resources/deployments", 
            "properties": { 
                "mode": "incremental", 
                "templateLink": {
                    "uri":"https://gist.githubusercontent.com/public-ip-template.json",
                    "contentVersion":"1.0.0.0"
                },
                "parameters": {                    
                    "publicIpAddressName": {
                        "value": "public-ip-test"
                    }
                }
            } 
        }

    ],
    "outputs": {
        "vmpublicIPName": {
            "type": "object",
            "value": "[reference('TestTemplate').outputs.publicIPName]"
        },
        "vmlocation": {
            "type": "object",
            "value": "[reference('TestTemplate').outputs.location]"
        }
    }
}

Связанный шаблон: -

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "publicIpAddressName": {
            "type": "string"
        }
    },
    "variables": {
        "location": "[resourceGroup().location]",
        "resourceGroupName": "[resourceGroup().name]"
    },
    "resources": [
        {
            "name": "[parameters('publicIpAddressName')]",
            "type": "Microsoft.Network/publicIpAddresses",
            "apiVersion": "2016-09-01",
            "location": "[variables('location')]",
            "properties": {
                "publicIpAllocationMethod": "Static"
            }
        }  

    ],
    "outputs": {
        "publicIPName": {
            "type": "string",
            "value": "[parameters('publicIpAddressName')]"
        },
        "location": {
            "type": "string",
            "value": "[variables('location')]"
        }
    }
}

person Galet    schedule 18.04.2017    source источник
comment
@ Walter-MSFT Я пробовал вышеуказанное. Тем не менее я получаю ту же ошибку.   -  person Galet    schedule 18.04.2017


Ответы (2)


Вы уверены, что URI связанного шаблона правильный и доступный? Согласно этому официальному документу

Значение URI для связанного файла параметров не может быть локальным файлом и должно включать http или https.

Я тестирую в своей лаборатории, я заменяю только ваш URI, как показано ниже:

 "templateLink": {
                    "uri":"https://gist.githubusercontent.com/Walter-Shui/d5387c0fc92f2e8df1c7157a2d5e54aa/raw/722d4a58107b2f617996ae237ceae445ef4342d9/test.json",
                    "contentVersion":"1.0.0.0"
                },

Ваш шаблон мне подходит.

введите описание изображения здесь

Как я могу распечатать вывод переменных, присутствующих в связанном шаблоне?

Да, это возможно. Как и ваш шаблон.

Есть ли способ распечатать все значения параметров развертывания связанного шаблона в основном шаблоне?

Вы можете использовать Azure cli 2.0 для получения значений связанных параметров.

az group deployment create --name shuitest1 --resource-group shuitest --template-file test.json --parameters '{"storageAccountName":{"value":"shuitest"}}'

{
  "id": "/subscriptions/********/resourceGroups/shuitest/providers/Microsoft.Resources/deployments/shuitest1",
  "name": "shuitest1",
  "properties": {
    "correlationId": "dbe16f35-0807-4627-b4b5-86c0a25c49ba",
    "debugSetting": null,
    "dependencies": [],
    "mode": "Incremental",
    "outputs": {
      "vmlocation": {
        "type": "Object",
        "value": {
          "type": "String",
          "value": "centralus"
        }
      },
      "vmpublicIPName": {
        "type": "Object",
        "value": {
          "type": "String",
          "value": "public-ip-test"
        }
      }
    },
    "parameters": {
      "storageAccountName": {
        "type": "String",
        "value": "shuitest"
      },
      "storageAccountType": {
        "type": "String",
        "value": "Standard_LRS"
      }
    },
    "parametersLink": null,
    "providers": [
      {
        "id": null,
        "namespace": "Microsoft.Storage",
        "registrationState": null,
        "resourceTypes": [
          {
            "aliases": null,
            "apiVersions": null,
            "locations": [
              "centralus"
            ],
            "properties": null,
            "resourceType": "storageAccounts"
          }
        ]
      },
      {
        "id": null,
        "namespace": "Microsoft.Resources",
        "registrationState": null,
        "resourceTypes": [
          {
            "aliases": null,
            "apiVersions": null,
            "locations": [
              null
            ],
            "properties": null,
            "resourceType": "deployments"
          }
        ]
      }
    ],
    "provisioningState": "Succeeded",
    "template": null,
    "templateLink": null,
    "timestamp": "2017-04-19T02:09:55.064156+00:00"
  },
  "resourceGroup": "shuitest"
}
person Shui shengbao    schedule 18.04.2017

"someName": {
    "type": "string",
    "value": "[variables('somevar')]"
},
  1. Таким же образом вы выводите параметры.

  2. Нет, это невозможно.

Итак, в чем вопрос, ваш шаблон выглядит хорошо. Я проверил это, и он работает

пс. ссылка в вашем шаблоне неправильная, это единственное, что не работает

person 4c74356b41    schedule 18.04.2017