microsoft / vscode-azurearmtools

Azure Resource Manager Tools for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools
MIT License
136 stars 81 forks source link

ResourceGroup deployment in a ManagementGroup scoped template generates validation error #1469

Open kwill-MSFT opened 2 years ago

kwill-MSFT commented 2 years ago

A Management Group template ("$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",) which has a nested deployment to deploy to a Resource Group scope fails validation because the tools think that 'ResourceGroup' is not a valid property.

The template at https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-management-group?tabs=azure-cli#deploy-to-subscription-and-resource-group shows this validation error:

Template validation failed: The template resource 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Common.Entities.TemplateGenericProperty`1[System.String]' at line '7' and column '9' is invalid. 'ResourceGroup' property is not allowed for for the current template deployment. Please see https://aka.ms/arm-template/#resources for usage details.

StephenWeatherford commented 1 year ago
{
  "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "nestedsubId": {
      "type": "string"
    },
    "nestedRG": {
      "type": "string"
    },
    "storageAccountName": {
      "type": "string"
    },
    "nestedLocation": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2021-04-01",
      "name": "nestedRG",
      "subscriptionId": "[parameters('nestedSubId')]",
      "resourceGroup": "[parameters('nestedRG')]",
      "dependsOn": [
        "nestedSub"
      ],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "resources": [
            {
              "type": "Microsoft.Storage/storageAccounts",
              "apiVersion": "2021-04-01",
              "name": "[parameters('storageAccountName')]",
              "location": "[parameters('nestedLocation')]",
              "kind": "StorageV2",
              "sku": {
                "name": "Standard_LRS"
              }
            }
          ]
        }
      }
    }
  ]
}
StephenWeatherford commented 1 year ago

Unfortunately blocked by https://github.com/microsoft/vscode-azurearmtools/issues/1458