Pankaj Rathi
Pankaj Rathi

Reputation: 75

ARM template for Azure Log Analytics Data Collector

I have been trying to create an ARM template for the Log Analytics Data collector API connection. I have almost got the ARM template but I'm unable to find where can I insert the Workspace Key value in the API connection to make it work.

Here is my ARM template for the API connection of Azure Log analytics Data collector.=

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  },
  "variables": {
  },
  "resources": [
    {
      "properties": {
        "displayName": "pankajtestlog",
        "statuses": [
          {
            "status": "Connected"
          }
        ],
        "customParameterValues": {},
        "nonSecretParameterValues": {
          "username": "yP4jrRxnB8EfXIO8Y27as+JbDMEUmIOk1K4QB5NuvTei9yELgzdjUCejWmwgb4AVpw81lg0NpOcpvdvmLM/Hqw=="
        },
        "createdTime": "2020-04-11T07:57:31.1911201Z",
        "changedTime": "2020-04-11T07:57:31.1911201Z",
        "api": {
          "name": "azureloganalyticsdatacollector",
          "displayName": "Azure Log Analytics Data Collector",
          "description": "Azure Log Analytics Data Collector will send data to any Azure Log Analytics workspace.",
          "iconUri": "https://connectoricons-prod.azureedge.net/azureloganalyticsdatacollector/icon_1.0.1274.1744.png",
          "brandColor": "#0072C6",
          "category": "Standard",
          "id": "/subscriptions/44357e6b-77a0-4b60-a817-27e62ffb6fdd/providers/Microsoft.Web/locations/usgovarizona/managedApis/azureloganalyticsdatacollector",
          "type": "Microsoft.Web/locations/managedApis"
        },
        "testLinks": []
      },
      "id": "/subscriptions/44357e6b-77a0-4b60-a817-27e62ffb6fdd/resourceGroups/RG-Guardian-POC/providers/Microsoft.Web/connections/azureloganalyticsdatacollector-1",
      "name": "azureloganalyticsdatacollector-1",
      "type": "Microsoft.Web/connections",
      "location": "usgovarizona",
      "apiVersion": "2016-06-01"
    }
  ],
  "outputs": {
  }
}

If you see the tempalte here the username parameter under nonSecretParameterValues is the Workspace ID but I'm unable to find what is the property to be added for Workspace shared key. The below screenshot would be helpful. Can someone help me add that property or you have any ARM for this. I have got this template from the ARMClient Tool.

enter image description here

Upvotes: 1

Views: 2054

Answers (2)

Jim Xu
Jim Xu

Reputation: 23111

If you need the log analytics workspace share key in the arm template, you can use the ARM template function listKeys to get it. For more details, please refer to the document

The expression should be like

listKeys(resourceId('<group name>','Microsoft.OperationalInsights/workspaces', '<space name>'), providers('Microsoft.OperationalInsights', 'workspaces').apiVersions[0]).primarySharedKey]

For example

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location":{
        "type": "string",
      "defaultValue": "[resourceGroup().location]"


    },
    "azureloganalyticsdatacollector_1_Connection_Name": {
      "type": "string",
      "defaultValue": "azureloganalyticsdatacollector"
    },
    "azureloganalyticsdatacollector_1_Connection_DisplayName": {
      "type": "string",
      "defaultValue": "test2"
    },
    "azureloganalyticsdatacollector_1_username": {
      "type": "string",
      "defaultValue":"fcbee0dd-1bb6-4c2b-a522-ea90b8606752",
      "metadata": {
        "description": "The unique identifier of the Azure Log Analytics workspace."
      },

    },
    "azureloganalyticsdatacollector_1_password": {
      "type": "securestring",
       "defaultValue":"5SFB4B54oiTKBZDcJrBgMw8c81hEaW7rYtC2A9wLh4/eATEOI4XxvGBVOor/ulmYRJePr3VqxACjBk7fvCpWbQ==",
      "metadata": {
        "description": "The primary or secondary key of the Azure Log Analytics workspace."
      }
    }
  },
  "variables": {},
  "resources": [
 {
      "type": "MICROSOFT.WEB/CONNECTIONS",
      "apiVersion": "2018-07-01-preview",
      "name": "[parameters('azureloganalyticsdatacollector_1_Connection_Name')]",
      "location": "[parameters('location')]",
      "properties": {
        "api": {
          "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', 'azureloganalyticsdatacollector')]"
        },
        "displayName": "[parameters('azureloganalyticsdatacollector_1_Connection_DisplayName')]",
        "parameterValues": {
          "username": "[parameters('azureloganalyticsdatacollector_1_username')]",
          "password": "[listKeys(resourceId('defaultresourcegroup-se','Microsoft.OperationalInsights/workspaces', 'DefaultWorkspace-e5b0fcfa-e859-43f3-8d84-5e5fe29f4c68-SE'), providers('Microsoft.OperationalInsights', 'workspaces').apiVersions[0]).primarySharedKey]"
        }
      }
    }
  ],
  "outputs": {

  }
}

enter image description here

Upvotes: 4

Raunak Jhawar
Raunak Jhawar

Reputation: 1651

You need the primary/secondary key of the log analytics workspace you have created. This can be found Advanced Settings blade of your workspace if you want a portal experience or can be found using the AZ CLI.

Upvotes: 1

Related Questions