honk
honk

Reputation: 591

How to create Application Insights API Key for annotations using ARM template

I'm trying to create Application Insights API keys from ARM template. I need to have the API key for write annotations created during resource deployment to have release annotations working during application deployment from Azure Devops.

I've tried to find information on how to get this working, but I can only find examples on how to use PowerShell or Azure REST API to create the keys.

What I need to get working is to create the API keys using the ARM template. I have tried numerous attempts with json similar to this without success;

 {
  "name": "[variables('applicationInsightsName')]",
  "type": "Microsoft.Insights/components",
  "location": "[resourceGroup().location]",
  "apiVersion": "2014-04-01",
  "tags": {
    "displayName": "[concat('Component ', variables('applicationInsightsName'))]"
  },
  "properties": {
    "applicationId": "[variables('applicationInsightsName')]"
  },
  "resources": [
    {
      "name": "action",
      "type": "apikeys",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-05-01",
      "properties": {
        "name": "Azure Devops Release Annotations",
        "linkedWriteProperties": [
          "[concat(resourceId('Microsoft.Insights/components', variables('applicationName')), '/annotations')]"
        ],
        "linkedReadProperties": []
      },
      "dependsOn": [
        "[resourceId('Microsoft.Insights/components', variables('applicationInsightsName'))]"
      ]
    }
  ]
}

The best information I've found so far is this, but it isn't much help.

Is it possible to have the API keys created using ARM templates?

Upvotes: 2

Views: 1668

Answers (2)

MaksimR
MaksimR

Reputation: 36

I suggest an easy way. You are able to use outputs with reference InstrumentationKey. Then you able to use it everywhere: another resource, linked template or use outputs for the next steps by Azure DevOps.

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string",
            "defaultValue": "[concat('stackoverflow-', uniqueString(resourceGroup().name))]"
        },
        "type": {
            "type": "string",
            "defaultValue": "web"
        },
        "requestSource": {
            "type": "string",
            "defaultValue": "IbizaAIExtension"
        }
    },
    "resources": [
        {
            "name": "[parameters('name')]",
            "type": "microsoft.insights/components",
            "location": "[resourceGroup().location]",
            "apiVersion": "2014-08-01",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Application_Type": "[parameters('type')]",
                "Flow_Type": "Redfield",
                "Request_Source": "[parameters('requestSource')]"
            }
        }
    ],
    "outputs":{
        "APPINSIGHTS_INSTRUMENTATIONKEY":{
            "type": "string",
            "value": "[reference(resourceId('Microsoft.Insights/components', parameters('name')), '2014-08-01').InstrumentationKey]"
        }
    }
}

I used it many times.

Upvotes: 1

4c74356b41
4c74356b41

Reputation: 72161

No this is not possible, ARM Templates only mimic PUT requests, whereas the Microsoft.Insights/Components/ApiKeys/Action is a POST request.

Upvotes: 5

Related Questions