I have a main template. Within that: I have a linked template creating application insights. and another linked template call to create a webapp.
Within the webapp linked template call, I want to pass the AIKey, as a parameter, but this is problematic. If i do:
"value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')),'2014-04-01').InstrumentationKey]"
This fails the first time because the reference value gets evaluated immediately, and the appinsights doesn't exist yet. This happens even if i use a depends-on on for the appinsights linked template resource call within the webapp.
So i thought maybe I can use a reference within a reference to prevent it from being evaluated too early, but this doesn't work - it seems you can't have a reference within a reference.
"value": "[reference(reference('AppInsights').outputs.resourceID.value,'2014-04-01').InstrumentationKey]"
I do not want to put the AI Key in the output of the linked template, since it would be putting it in plaintext. Is there a way to achieve what I'm trying to do?
Here are some code snippets, it's a single template but the template is very large so I didn't include everything:
Call AI nested template:
{
"name": "AppInsights",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('AppInsightsTemplatePath')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"tagValues": {
"value": "[parameters('tagValues')]"
},
"workspaceId": {
"value": "[parameters('workspaceId')]"
},
"appInsightsName": {
"value": "[variables('appInsightsName')]"
}
}
}
},
Call WebAPP Template:
{
"name": "WebApp",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [
"AppInsights",
"AppServicePlan"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('WebAppTemplatePath')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"siteConfig": {
"value": {
"netFrameworkVersion": "v4.7",
"phpVersion": "",
"pythonVersion": "",
"javaVersion": "",
"nodeVersion": "",
"linuxFxVersion": "",
"use32BitWorkerProcess": "False",
"webSocketsEnabled": "False",
"alwaysOn": "True",
"managedPipelineMode": "Integrated",
"remoteDebuggingEnabled": "False",
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')),'2014-04-01').InstrumentationKey]"
}
],
"connectionStrings": [],
"defaultDocuments": [],
"handlerMappings": [],
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": "True",
"virtualDirectories": ""
}
],
"minTlsVersion": "1.2"
}
}
}
}
},
Here's the error: "code": "ResourceNotFound", "message": "The Resource 'Microsoft.Insights/components/MyAppInsightsName' under resource group 'MyResourceGroup' was not found."