1

Does any know how I can use the reference function to reference a existing resourcegroup in a azure resource templates.

I would like to know the location of a specfic resource (West europe, West us etc) because I needed as input for an another resource. The resource that I reference is not in the same resourcegroup

Geoffrey Samper
  • 497
  • 4
  • 14

2 Answers2

1

If we want to create the traffic manager with ARM and config azureEndpoints endpoint. We no need to add location property. We can get that by target resource id, The following is my test code, it works correctly for me.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "variables": {
    "tmApiVersion": "2015-11-01"
  },
  "resources": [
    {
      "apiVersion": "[variables('tmApiVersion')]",
      "type": "Microsoft.Network/trafficManagerProfiles",
      "name": "azureendpointexample",
      "location": "global",
      "properties": {
        "profileStatus": "Enabled",
        "trafficRoutingMethod": "Performance",
        "dnsConfig": {
          "relativeName": "azureendpointexample",
          "ttl": 30
        },
        "monitorConfig": {
          "protocol": "http",
          "port": 80,
          "path": "/"
        },
        "endpoints": [
          {
            "name": "tomtest",
            "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
            "properties": {
              "endpointStatus": "Enabled",
              "endpointMonitorStatus": null,
              "targetResourceId": "[resourceId('resourcegroup', 'Microsoft.Web/sites/', 'websitename')]",
              "target": "azureendpointexample.azurewebsites.net",
              "weight": 1,
              "priority": 1
            }
          }
        ]
      }
    }
  ]
}

Check it from the Azure portalenter image description here.

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
0

Not all resources support returning the location (keep in mind some are geo-redundant) maybe more detail behind the question, i.e. what resources are you trying to connect, might help.

Here's an example of getting the primary storage location:

[reference(resourceId(parameters('storageAccountResourceGroup'), 'Microsoft.Storage/storageAccounts/', parameters('storageAccountName'), '2016-01-01').primaryLocation]

But for something like a VM's VHD, a managed disk would be easier... So knowing more about the scenario might lead to a better solution...

bmoore-msft
  • 8,376
  • 20
  • 22