gpt4 book ai didi

json - ARM listKeys() 函数 - 如何检索 OMS/OpsInsight 工作区 key ?

转载 作者:行者123 更新时间:2023-12-04 19:01:12 25 4
gpt4 key购买 nike

作为模板的一部分,我想检索 OMS/Operational Insights 工作区的 SharedKey,而不必将其作为参数传递。

这可能吗?我正在关注文档 here

Microsoft.OperationalInsights/workspaces/ 资源提供程序似乎没有任何 list* 提供程序操作,并且我找不到其他任何引用:

Get-AzureRmProviderOperation -OperationSearchString *  | where {$_.Operation -like "*operational*sharedkeys*"} | FT Operation

Microsoft.OperationalInsights/workspaces/sharedKeys/action

我想要的用法:

"variables": { workspaceKey: "[listKeys(parameters('workspaceResourceId'), '2015-05-01-preview').primarySharedKey]" }

同时,假设实际上不支持此功能,我添加了 a request for it on the Log Analytics UserVoice site

最佳答案

Per Ryan Jones ,针对 OMS 工作区的 [listKeys()] 将按预期工作,并返回具有 primarySharedKey secondarySharedKey 属性的 JSON 对象:

"outputs": {
"listKeys": {
"value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview')]",
"type": "object"
}
}

产量:

{
"primarySharedKey":"",
"secondarySharedKey":""
}
<小时/>

重要警告:

listKeys() can not be specified in the variables section of an ARM template, since it derives its value from a runtime state.

See this blog post for how to use a Linked Template, specified as a resource, in order to retrieve the output value and assign it to a property in another resource.

或者,您可以直接使用它。这是我的最终模板:
(实际上并不将 key 保留在输出中!)

{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceResourceId": { "type": "string" },
"virtualMachines": { "type": "array" }
},
"variables": {
"extensionType": {
"Windows": "MicrosoftMonitoringAgent",
"Linux": "OmsAgentForLinux"
}
},
"resources": [
{
"copy": {
"name": "VMMonitoringExtensionsCopy",
"count": "[length(parameters('virtualMachines'))]"
},
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('virtualMachines')[copyIndex()].location]",
"name": "[concat(parameters('virtualMachines')[copyIndex()].name, '/Microsoft.EnterpriseCloud.Monitoring')]",
"properties": {
"publisher": "Microsoft.EnterpriseCloud.Monitoring",
"type": "[variables('extensionType')[parameters('virtualMachines')[copyIndex()].osType]]",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": {
"workspaceId": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]"
},
"protectedSettings": {
"workspaceKey": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]"
}
}
}
],
"outputs": {
"workspaceCustomerId": {
"value": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]",
"type": "string"
},
"workspacePrimarySharedKey": {
"value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]",
"type": "securestring"
},
"workspaceSecondarySharedKey": {
"value": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').secondarySharedKey]",
"type": "securestring"
}
}
}

数组参数virtualMachines遵循以下架构:

[
{ "name": "", "location": "", "osType": "" }
]

关于json - ARM listKeys() 函数 - 如何检索 OMS/OpsInsight 工作区 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37292530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com