location property is not allowed for a deployment at resource group scope

Viewed 674

I created linked ARM template and trying to deploy but I am getting below error.

I am deploying Sql Server and Server Database using linked templates. Individual ARM (Sql Server and sql database is working fine).

Error: InvalidDeployment; Message=The 'location' property is not allowed for a deployment at resource group scope. Please see https://aka.ms/deploy-to-subscription for usage details.

If I remove location and trying to deploy I am getting below error.

The location property is required for this definition

Is my mistake is in Schema version or api version or something?

New-AzResourceGroupDeployment -Name "ARMLinkedDeployment" -ResourceGroupName "Test-POC-RG" -TemplateFile ".......\MainTemplates\SqlApp\azuredeploy.json" -TemplateParameterFile ".....\MainTemplates\SqlApp\parameters.json"

parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "sqlserver_linkedTemplatepath": {
        "value": "https://stvirtuosotest.blob.core.windows.net/armlinkedtemplates/azuredeploysql.json"
    },
    "sqldb_linkedTemplatepath": {
        "value": "https://stvirtuosotest.blob.core.windows.net/armlinkedtemplates/azuredeploysqldb.json"
    },
    "sqlserver_parameters_linkedTemplatepath": {
        "value": "https://stvirtuosotest.blob.core.windows.net/armlinkedtemplates/azuredeploy.sqlparameters.json"
    },
    "sqldb_parameters_linkedTemplatepath": {
        "value": "https://stvirtuosotest.blob.core.windows.net/armlinkedtemplates/azuredeploy.sqldbparameters.json"
    }
}
}

azuredeploy.json file

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "sqlserver_linkedTemplatepath": {
        "type": "string",
        "metadata": {
            "description": "The sql server arm template json file path from storage account.."
        }
    },
    "sqldb_linkedTemplatepath": {
        "type": "string",
        "metadata": {
            "description": "The sql database deploy arm template json file path from storage account."
        }
    },
    "sqldb_parameters_linkedTemplatepath": {
        "type": "string",
        "metadata": {
            "description": "The sql database arm parameters file json file path from storage account."
        }
    },
    "sqlserver_parameters_linkedTemplatepath": {
        "type": "string",
        "metadata": {
            "description": "The sql server arm parameters json file path from storage account."
        }
    }
},

"resources": [
    {
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2020-06-01",
        "name": "sqlDbDeployment",
        "resourceGroup": "[resourceGroup().name]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[parameters('sqldb_linkedTemplatepath')]",
                "contentVersion": "1.0.0.0"
            },
            "parametersLink": {
                "contentVersion": "1.0.0.0",
                "uri": "[parameters('sqldb_parameters_linkedTemplatepath')]"
            }
        },
        "dependsOn": [
            "sqlServerDeployment"
        ]
    },
    {
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2020-06-01",
        "name": "sqlServerDeployment",
        "resourceGroup": "[resourceGroup().name]",
        "properties": {
            "mode": "Incremental",
            "templateLink": {
                "uri": "[parameters('sqlserver_linkedTemplatepath')]",
                "contentVersion": "1.0.0.0"
            },
            "parametersLink": {
                "contentVersion": "1.0.0.0",
                "uri": "[parameters('sqlserver_parameters_linkedTemplatepath')]"
            }
        }
    }

],
"outputs": {
    "sqldbresourceid": {
        "type": "object",
        "value": "[reference('sqlDbDeployment').outputs.resourceGroup.resourceId]"
    },
    "sqlserverresourceid": {
        "type": "object",
        "value": "[reference('sqlServerDeployment').outputs.resourceGroup.resourceId]"
    }
}
}
1 Answers

Here is how I fixed the same issue.

parameters.json file

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "value": "eastus2"
        }
    }
}

azuredeploy.json file

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2021-04-01",
            "name": "deployment1",
            "resourceGroup": "[resourceGroup().name]",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "relativePath": "templates/template.json"
                },
                "parameters": {
                    "location": {
                        "value" : "[parameters('location')]"
                    }
                }
            }
        }
    ]
}

So the location can be used from the template.json as required.

Reference: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-test-cases#location-uses-parameter

Related