0

I have an existing OMS Log Analytics Workspace. The Workspace ID is a guid. This is the only thing I am able to use due to an existing project. Using this guid I need to get hold of the Workspace Name example "myWorkspace" in the arm template. I am allowed to pass the guid as the parameter to the arm template. The Guid actually is a customerId property if I look in the Json and ResourceId maps to the Workspace Name which begins with /subscription/xx-xxx-xxx-xxx/......../myWorkspace.

I need to get hold of this Workspace Name (ResourceId) from guid (customerId). Please let me know if I can do this or not? Really struggling to get this working...

gigatt
  • 105
  • 7
chugh97
  • 9,602
  • 25
  • 89
  • 136
  • do you want to get the workspace name via programming, like using c#? – Ivan Glasenberg Aug 20 '20 at 01:01
  • No using ARM template only @Ivan Yang – chugh97 Aug 20 '20 at 10:41
  • @chugh97 - Can you please help explain your scenario better on why you want to get workspace name with in the ARM template based on workspace ID ? and what's limiting you to fetch the workspacename based on the workspaceID via powershell or other ways before invoking the ARM template ? to best of knowledge the REST API doesn't have the parameter to fetch using workspace ID https://learn.microsoft.com/en-us/rest/api/loganalytics/workspaces/get , it only has workspacename – bharathn-msft Sep 01 '20 at 00:22

2 Answers2

2

I am not sure what you want to achieve but I have used multiple times the Log Analytics Workspace with azure ARM. An example is how to retrieve the workspace key and workspace Id to connect a vm with the workspace.

See the code bellow:

  {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(parameters('vmName'), '/OMSExtension')]",
        "apiVersion": "2018-06-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName') )]"
        ],
        "properties": {
            "publisher": "Microsoft.EnterpriseCloud.Monitoring",
            "type": "OmsAgentForLinux",
            "typeHandlerVersion": "1.7",
            "autoUpgradeMinorVersion": true,
            "settings": {
                "workspaceId": "[reference(resourceId(parameters('logAnalyticsRG'), 'Microsoft.OperationalInsights/workspaces/', parameters('logAnalyticsName')), '2015-03-20').customerId]"
            },
            "protectedSettings": {
                "workspaceKey": "[listKeys(resourceId(parameters('logAnalyticsRG'), 'Microsoft.OperationalInsights/workspaces/', parameters('logAnalyticsName')), '2015-03-20').primarySharedKey]"
            }
        }
    }

Everything depends from the scenario you, but this is the way how to retrieve the workspace id and key.

Llazar
  • 3,167
  • 3
  • 17
  • 24
1

You can get it from ARG (Azure resource graph) pretty easily, but there's no way i know of to look it up IN an ARM template itself. you'd probably have to look up the id outside the template and pass it in as a parameter?

https://learn.microsoft.com/en-us/azure/governance/resource-graph/concepts/explore-resources

Resources 
| where type =~ "microsoft.operationalinsights/workspaces"
| where properties.customerId == "00000000-0000-0000-0000-00000000000"
| project id, name
John Gardner
  • 24,225
  • 5
  • 58
  • 76