Can we get the connection string for an Application Insights in an Azure Resource Group Template?

Viewed 1164

Can we retrieve the connection string for an Application Insights instance in an Azure Resource Group template ?

I can retrieve instrumentation key by below code but when I try to get connectionString with same or Listkey than it's giving error.

"outputs": {
    "MyAppInsightsInstrumentationKey": {
        "value": "[reference(resourceId('Microsoft.Insights/components', variables('myAppInsightsInstanceName')), '2014-04-01').connectionString]",
        "type": "string"
    }
}

Error : {"error":{"code":"InvalidTemplate","message":"Deployment template validation failed: 'The template variable 'myAppInsightsInstanceName' is not found. Please see https://aka.ms/arm-template/#variables for usage details.'.","additionalInfo":[{"type":"TemplateViolation","info":{"lineNumber":95,"linePosition":40,"path":"properties.template.outputs.MyAppInsightsInstrumentationKey"}}]}}

1 Answers

As commented by @ZakiMa, you need to use a newer API version.

Something like that should work:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "MyAppInsightsInstanceName": "<My App Insights Instance Name>"
  },
  "outputs": {
    "MyAppInsightsConnectionString": {
      "value": "[reference(resourceId('Microsoft.Insights/components', variables('MyAppInsightsInstanceName')), '2020-02-02').ConnectionString]",
      "type": "string"
    }
  },
  "resources": []
}
Related