JoeBrockhaus JoeBrockhaus - 1 year ago 188
JSON Question

ARM listKeys() Function - How to retrieve OMS/OpsInsight Workspace keys?

As part of a template I want to retrieve the SharedKeys of an OMS / Operational Insights Workspace, rather than having to pass it in as a parameter.

Is this possible? I'm following the documentation here

It does not appear that the

resource provider has any
provider operations, and I can't find any reference for other:

Get-AzureRmProviderOperation -OperationSearchString * | where {$_.Operation -like "*operational*sharedkeys*"} | FT Operation


My desired usage:

"variables": { workspaceKey: "[listKeys(parameters('workspaceResourceId'), '2015-05-01-preview').primarySharedKey]" }

In the meantime, assuming this isn't actually supported, I added a request for it on the Log Analytics UserVoice site

Answer Source

Per Ryan Jones, [listKeys()] against the OMS Workspace will work as expected and return a JSON object with primarySharedKey & secondarySharedKey properties:

"outputs": {
    "listKeys": {
        "value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview')]",
        "type": "object"



Important Caveat:

listKeys() can not be specified in the variables section of an ARM template, since it derives its value from a runtime state.

See this blog post for how to use a Linked Template, specified as a resource, in order to retrieve the output value and assign it to a property in another resource.

Alternatively, you can use it directly. Here is my final template:

  "$schema": "",
  "contentVersion": "",
  "parameters": {
    "workspaceResourceId": { "type": "string" },
    "virtualMachines": { "type": "array" }
  "resources": [
      "copy": {
        "name": "VMMonitoringExtensionsCopy",
        "count": "[length(parameters('virtualMachines'))]"
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2015-05-01-preview",
      "location": "[parameters('virtualMachines')[copyIndex()].location]",
      "name": "[concat(parameters('virtualMachines')[copyIndex()].name, '/Microsoft.EnterpriseCloud.Monitoring')]",
      "properties": {
        "publisher": "Microsoft.EnterpriseCloud.Monitoring",
        "type": "MicrosoftMonitoringAgent",
        "typeHandlerVersion": "1.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "workspaceId": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]"
        "protectedSettings": {
          "workspaceKey": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]"
  "outputs": {
    "workspaceCustomerId": {
      "value": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]",
      "type": "string"
    "workspacePrimarySharedKey": {
      "value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]",
      "type": "securestring"
    "workspaceSecondarySharedKey": {
      "value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').secondarySharedKey]",
      "type": "securestring"