本文介绍了使用Azure资源管理器将已创建的Azure应用程序洞察与应用程序服务中的API应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Terraform脚本在不同的资源组中创建应用程序洞察。当我创建Web应用程序或API应用程序时,我希望在中关联以前创建的App Insight。我正在传递之前在Web应用程序中创建的应用程序洞察的Intrumentation键,但它们没有链接。当我尝试从创建Web应用程序的同一ARM模板中创建应用程序洞察时,它工作得很好。
工作正常的手臂示例:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webSiteName": {
"type": "string",
"minLength": 1,
"defaultValue": "TestWebsiteWithAppInsight",
"metadata": {
"description": "Describes the name of the new website"
}
},
"appInsightsName": {
"type": "string",
"minLength": 1,
"defaultValue": "TestAppInsight",
"metadata": {
"description": "Describes the name of the Application Insights resource"
}
},
"hostingPlanName": {
"type": "string",
"minLength": 1,
"defaultValue": "sudipta-ase-plan1"
},
"skuName": {
"type": "string",
"defaultValue": "F1",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 4,
"minValue": 1,
"metadata": {
"description": "Describes plan's instance count"
}
}
},
"variables": {
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "HostingPlan"
},
"sku": {
"name": "[parameters('skuName')]",
"capacity": "[parameters('skuCapacity')]"
},
"properties": {
"name": "[parameters('hostingPlanName')]"
}
},
{
"apiVersion": "2015-08-01",
"name": "[parameters('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"[resourceId('microsoft.insights/components/', parameters('appInsightsName'))]"
],
"properties": {
"name": "[parameters('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
}
},
{
"apiVersion": "2015-08-01",
"name": "Microsoft.ApplicationInsights.AzureWebSites",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
}
}
]
},
{
"apiVersion": "2014-04-01",
"name": "[parameters('appInsightsName')]",
"type": "Microsoft.Insights/components",
"location": "East US",
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', parameters('webSiteName'))]": "Resource",
"displayName": "AppInsightsComponent"
},
"properties": {
"applicationId": "[parameters('appInsightsName')]"
}
}
]
}
无法工作的手臂示例:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webSiteName": {
"type": "string",
"minLength": 1,
"defaultValue": "TestWebsiteWithAppInsight",
"metadata": {
"description": "Describes the name of the new website"
}
},
"appInsightsName": {
"type": "string",
"minLength": 1,
"defaultValue": "test123",
"metadata": {
"description": "Describes the name of the Application Insights resource"
}
},
"hostingPlanName": {
"type": "string",
"minLength": 1,
"defaultValue": "sudipta-ase-plan1"
},
"skuName": {
"type": "string",
"defaultValue": "F1",
"allowedValues": [
"F1",
"D1",
"B1",
"B2",
"B3",
"S1",
"S2",
"S3",
"P1",
"P2",
"P3",
"P4"
],
"metadata": {
"description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
}
},
"skuCapacity": {
"type": "int",
"defaultValue": 4,
"minValue": 1,
"metadata": {
"description": "Describes plan's instance count"
}
}
},
"variables": {
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "HostingPlan"
},
"sku": {
"name": "[parameters('skuName')]",
"capacity": "[parameters('skuCapacity')]"
},
"properties": {
"name": "[parameters('hostingPlanName')]"
}
},
{
"apiVersion": "2015-08-01",
"name": "[parameters('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
],
"properties": {
"name": "[parameters('webSiteName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "['99f330eb-ae79-4070-b8b6-e50d01f6e391123134434sdfdadaa']"
}
},
{
"apiVersion": "2015-08-01",
"name": "Microsoft.ApplicationInsights.AzureWebSites",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
}
}
]
}
]
}
推荐答案
请将代码从"APPINSIGHTS_INSTRUMENTATIONKEY": "['99f330eb-ae79-4070-b8b6-e50d01f6e391123134434sdfdadaa']"
更改为"APPINSIGHTS_INSTRUMENTATIONKEY": "99f330eb-ae79-4070-b8b6-e50d01f6e391123134434sdfdadaa"
。
for字符串值不应为方括号:[and]。方括号[和]用于ARM template functions。
更新:
根据我的测试,如果想要链接到Azure WebApp,还需要添加以下代码。它还可以与现有的appInsightsName一起使用。
{
"apiVersion": "2014-04-01",
"name": "[parameters('appInsightsName')]",
"type": "Microsoft.Insights/components",
"location": "East US",
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', parameters('webSiteName'))]": "Resource",
"displayName": "AppInsightsComponent"
},
"properties": {
"applicationId": "[parameters('appInsightsName')]"
}
}
我使用的ARM模板
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverFarmName": {
"type": "string",
"defaultValue": "tomfreePlan"
},
"serverFarmResourceGroup": {
"type": "string",
"defaultValue": "CXP-TomSun"
}},
"variables": {
"webSiteName": "[concat('TomARMTest-1', uniqueString(resourceGroup().id))]",
"existingApplicationInsight": "tomarmtestdemo"
},
"resources": [
{
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "southcentralus",
"apiVersion": "2015-08-01",
"dependsOn": [
],
"tags": {
"[concat('hidden-related:', resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName')))]": "Resource",
"displayName": "TomARMTest"
},
"properties": {
"name": "[variables('webSiteName')]",
"serverFarmId": "[resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('webSiteName'))]",
"[resourceId('microsoft.insights/components/', variables('existingApplicationInsight'))]"
],
"tags": {
"displayName": "tomtest"
},
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "xxxxxxxxxxx"
}
},
{
"apiVersion": "2015-08-01",
"name": "Microsoft.ApplicationInsights.AzureWebSites",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
],
"properties": {
}
}
]
},
{
"apiVersion": "2014-04-01",
"name": "[variables('existingApplicationInsight')]",
"type": "Microsoft.Insights/components",
"location": "East US",
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
"displayName": "AppInsightsComponent"
},
"properties": {
"applicationId": "[variables('existingApplicationInsight')]"
}
}
],
"outputs": {}
}
这篇关于使用Azure资源管理器将已创建的Azure应用程序洞察与应用程序服务中的API应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!