azure - 我们能否在 Azure 资源组模板中获取 Application Insights 的连接字符串?
问题描述
我们可以在 Azure 资源组模板中检索 Application Insights 实例的连接字符串吗?
我可以通过下面的代码检索检测密钥,但是当我尝试使用相同或 Listkey 获取 connectionString 时,它会给出错误。
"outputs": {
"MyAppInsightsInstrumentationKey": {
"value": "[reference(resourceId('Microsoft.Insights/components', variables('myAppInsightsInstanceName')), '2014-04-01').connectionString]",
"type": "string"
}
}
错误:{"error":{"code":"InvalidTemplate","message":"部署模板验证失败:'找不到模板变量'myAppInsightsInstanceName'。请参阅https://aka.ms/arm-template /#variables使用详情。'.","additionalInfo":[{"type":"TemplateViolation","info":{"lineNumber":95,"linePosition":40,"path":"properties.template .outputs.MyAppInsightsInstrumentationKey"}}]}}
解决方案
正如@ZakiMa 所评论的,您需要使用更新的 API 版本。
像这样的东西应该工作:
{
"$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": []
}
推荐阅读
- amazon-web-services - AWS SSO - “请求 nameID 格式与我们的记录不匹配”
- python - 有没有办法在 groupby() 之后访问分组列?
- drupal-8 - Drupal 8 Webform 为上传的文件名添加前缀
- javascript - 如何在链接中找到消息
- javascript - 页面重定向有效,但功能无效
- c++ - 多线程环境中用户空间线程和 std::thread 之间的上下文切换
- node.js - 如何与 forEach 同时执行承诺?
- javascript - Vue.js 模板中的动态参数是否可行?
- jms - 在 server.xml 中为 solace 资源适配器配置 jmsConnectionFactory 不起作用
- java - Eclipse 不导入 bukkit