更新 Microsoft 的 ARM API 后,现在可以直接从 ARM 部署输出中检索 Azure 功能键。
示例
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServiceName": {
"type": "string"
}
},
"variables": {
"appServiceId": "[resourceId('Microsoft.Web/sites', parameters('appServiceName'))]"
},
//... implementation omitted
"outputs": {
"functionKeys": {
"type": "object",
"value": "[listkeys(concat(variables('appServiceId'), '/host/default'), '2018-11-01')]"
}
}
}
输出
Outputs 属性将包含一个 Newtonsoft.Json.Linq.JObject 条目,其中包含 Azure 函数的所有键,即主键、系统键和功能键(包括默认键)。不幸的是,JObject 与部署变量类型结合起来有点曲折,应该警告您,它是区分大小写的。 (如果您在 PowerShell 中工作,可以将其发送到 hashtables 以供使用。请参阅下面的奖励。)
$results = New-AzResourceGroupDeployment...
$keys = results.Outputs.functionKeys.Value.functionKeys.default.Value
奖金
下面的代码去掉了额外的.Value 调用。
function Convert-OutputsToHashtable {
param (
[ValidateNotNull()]
[object]$Outputs
)
$Outputs.GetEnumerator() | ForEach-Object { $ht = @{} } {
if ($_.Value.Value -is [Newtonsoft.Json.Linq.JObject]) {
$ht[$_.Key] = ConvertFrom-Json $_.Value.Value.ToString() -AsHashtable
} else {
$ht[$_.Key] = $_.Value.Value
}
} { $ht }
}