Как получить имя группы ресурсов при использовании New-AzureRmDeployment и связанного шаблона ARM для создания группы ресурсов и ресурса? - PullRequest
0 голосов
/ 12 сентября 2018

При развертывании связанного ARM, настроенного с помощью основного шаблона ARM с помощью командлета New-AzureRmDeployment, я получаю сообщение об ошибке при попытке использовать функцию и свойство resourceGroup().name.Сообщение об ошибке:

Unable to process template language expressions for resource
'/subscriptions/<subscriptionGuid>/resourceGroups/Zxy- 
Test/providers/Microsoft.Resources/deployments/storageDeployment' at line 
'29' and column '5'. 'The template function
'RESOURCEGROUP' is not expected at this location.`

В качестве альтернативы я попытался использовать функцию resourceId(...) без вызова функции группы ресурсов, но это дает неверный идентификатор ресурса, где информация о группе ресурсов отсутствует и отсутствуетсопоставьте идентификатор ресурса, полученный на портале Azure.

например,

"value": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"

Результат с отсутствующей группой ресурсов:

/subscriptions/<subscriptionGuid>/providers/Microsoft.Storage/storageAccounts/linktestdata

Вот то, что я ожидаю, что такжесообщается порталом Azure

/subscriptions/<subscriptionGuid>/resourceGroups/Zxy-Test/providers/Microsoft.Storage/storageAccounts/linktestdata

В качестве примера для иллюстрации проблемы у меня есть следующие шаблоны TestMaster.json и TestLinked0.json.

TestMaster.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "linkedTemplateUri": {
      "type": "string",
      "metadata": {
        "description": "URI to the linked ARM template file."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2018-05-01",
      "name": "testMasterDeployment",
      "type": "Microsoft.Resources/deployments",
      "location": "West US",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[parameters('linkedTemplateUri')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "tagValues": { "value": {
              "TagA": "A-Tag",
              "TagB": "B-Tag"
          }}
        }
      }
    }
  ],
  "outputs": {
    "messageFromMaster00": {
      "type": "string",
      "value": "Master-00 reporting"
    },
    "messageFromLinkedTemplate": {
      "type": "object",
      "value": "[reference('testMasterDeployment').outputs.messageFromNestedTemplate]"
    }
  }
}

TestLinked0.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "rgName": {
      "defaultValue": "Zxy-Test",
      "type": "string"
    },
    "location": {
      "defaultValue": "West US",
      "type": "string"
    },
    "tagValues": {
      "type": "object"
    }
  },
  "variables": {
    "storageName": "linktestdata"
  },
  "resources": [
    {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2018-05-01",
      "location": "[parameters('location')]",
      "name": "[parameters('rgName')]",
      "properties": {},
      "tags": "[parameters('tagValues')]"
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2017-05-10",
      "name": "storageDeployment",
      "resourceGroup": "[parameters('rgName')]",
      "dependsOn": [
        "[resourceId('Microsoft.Resources/resourceGroups/', parameters('rgName'))]"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.Storage/storageAccounts",
              "apiVersion": "2017-10-01",
              "name": "[variables('storageName')]",
              "location": "[parameters('location')]",
              "tags": "[parameters('tagValues')]",
              "kind": "StorageV2",
              "sku": {
                "name": "Standard_LRS"
              }
            }
          ],
          "outputs": {
            "storageAccount": {
              "type": "string",
              "value": "[variables('storageName')]"
            },
            "resourceInfo0": {
              "type": "string",
              "value": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
            },
            "resourceInfo1": {
              "type": "string",
              "value": "[resourceId(resourceGroup().name, 'Microsoft.Storage/storageAccounts', variables('storageName'))]"
            }
          }
        }
      }
    }
  ],
  "outputs": {
    "messageFromNestedTemplate": {
      "type": "object",
      "value": "[reference('storageDeployment').outputs]"
    }
  }
}

PowerShell, используемый для развертывания шаблонов ARM:

$uri = 'https://<containername>.blob.core.windows.net/azure-resource-templates/TestMaster.json'
$linkedTemplateUri = 'https://<containername>.blob.core.windows.net/azure-resource-templates/TestLinked0.json'
New-AzureRmDeployment -Location 'West US' -TemplateUri $uri -linkedTemplateUri $linkedTemplateUri

1 Ответ

0 голосов
/ 12 сентября 2018

Я нашел документацию Microsoft, в которой говорится, что функция resourceGroup () не поддерживается. для развертываний уровня подписки на https://docs.microsoft.com/en-us/azure/azure-resource-manager/deploy-to-subscription#using-template-functions. Используемый мной командлет - New-AzureRmDeployment, который используется для развертывания ресурсов в текущей области подписки. Похоже, мне нужно выбрать другой подход.

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