How to define a specific resource group in a nested Azure Resource Manager template

Does anyone know how to place resources in an ARM template in specific and different resource groups? It can be storage in one RG and a network in another, created in the same or different templates (for example, nested).

See below for details.


Read the Best Practice Guide Best Practices for ARM Templates and the white paper World-Class ARM Templates and Proven Practices There is a recommendation that the various deployment elements should be located in separate resource groups. For example, in an IaaS solution, your DCs can be hosted in Admin RG, your server servers in another, and your desktop computers in a third.

I'm currently trying to deploy such a solution through nested templates, and I came across a problem when all created elements are automatically placed inside the resource group selected when the process was turned off (i.e. parent template). I looked through all the online documentation, but I can’t find a way to force the resources created in the template into a specific resource group. Has anyone done this?

+4
source share
2 answers

For anyone who finds this on google (like me):

ARM. Microsoft , : https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-cross-resource-group-deployment .

, . MS:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storagePrefix": {
            "type": "string",
            "maxLength": 11
        },
        "secondResourceGroup": {
            "type": "string"
        },
        "secondSubscriptionID": {
            "type": "string",
            "defaultValue": ""
        },
        "secondStorageLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        }
    },
    "variables": {
        "firstStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]",
        "secondStorageName": "[concat(parameters('storagePrefix'), uniqueString(parameters('secondSubscriptionID'), parameters('secondResourceGroup')))]"
    },
    "resources": [
        {
            "apiVersion": "2017-05-10",
            "name": "nestedTemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('secondResourceGroup')]",
            "subscriptionId": "[parameters('secondSubscriptionID')]",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "type": "Microsoft.Storage/storageAccounts",
                            "name": "[variables('secondStorageName')]",
                            "apiVersion": "2017-06-01",
                            "location": "[parameters('secondStorageLocation')]",
                            "sku":{
                                "name": "Standard_LRS"
                            },
                            "kind": "Storage",
                            "properties": {
                            }
                        }
                    ]
                },
                "parameters": {}
            }
        },
        {
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[variables('firstStorageName')]",
            "apiVersion": "2017-06-01",
            "location": "[resourceGroup().location]",
            "sku":{
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {
            }
        }
    ]
}
+2

. , API- REST API- Azure , .

ARM , , , , , . Azure Service Management, .

, Azure .

+5

Source: https://habr.com/ru/post/1628288/


All Articles