[英]How to add a default function key with ARM template for a deployment slot in Azure Functions
我想在 azure 的部署槽中添加一个默认的 function 密钥。 因此,我将它添加到我的模板中,如下所示:
...,
{
"type": "Microsoft.Web/sites/slots/functions/keys",
"dependsOn":[
"[resourceId('Microsoft.Web/sites/slots', variables('apiServiceName'),'deploy')]"
],
"apiVersion": "2018-02-01",
"name": "[concat(variables('apiServiceName'),'/deploy/default/eventgrid')]",
"properties": {
"name": "eventgrid"
}
},...
不幸的是,我找不到如何让它工作,这是我能找到的最接近模板失败的方法(更少的段使模板无效)现在我得到这个错误:
NotFound:创建或更新 function 密钥时出错。
The API docs explain how it works, and I think it matches what I have here for the ARM template, but I can't seem to figure out why I get a not found error... Anyone ever tried this for an azure function slot ? 我可以让它为生产槽工作:
...,
{
"type": "Microsoft.Web/sites/host/functionKeys",
"dependsOn":[
"[resourceId('Microsoft.Web/sites', variables('apiServiceName'))]"
],
"apiVersion": "2018-11-01",
"name": "[concat(variables('apiServiceName'), '/default/eventgrid')]",
"properties": {
"name": "event-grid"
}
},...
任何帮助表示赞赏。
这对我有用。 我认为您在 name 属性中缺少插槽名称:
{
"type": "Microsoft.Web/sites/slots/host/functionKeys",
"apiVersion": "2018-11-01",
"name": "[concat(variables('functionAppName'), '/staging', '/default/key')]",
"properties": {
"name": "key",
"value": "[parameters('key')]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites/slots', variables('functionAppName'), 'staging')]"
]
},
我还不能发表评论,所以我不得不写一个答案:-(我想添加一件我发现在使用上述答案时非常有用的小东西。我希望看到这个问题的人可能会发现它对在这里直接看到这个链接。
在尝试使用一个 ARM 模板部署多个环境时,我使用了上述答案并通过在参数文件中为每个环境创建一个参数来扩展它:
"parameters": {
"subscription": {
"value": "<mySub>"
},
"env": {
"value": "<env>"
},
"devHostKey": {
"reference": {
"keyVault": {
"id": "/subscriptions/<mySubID>/resourceGroups/<myKvRG>/providers/Microsoft.KeyVault/vaults/<KvName>"
},
"secretName": "<KeyName>"
}
},
"accHostKey": { .... },
"prdHostKey": {..... }
}
然后在我使用的 ARM 模板中
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscription": {
"type": "string"
},
"env": {
"type": "string"
},
"devHostKey": {
"type": "securestring"
},
"accHostKey": {
"type": "securestring"
},
"prdHostKey": {
"type": "securestring"
}
},
"resources":[
{"type": "Microsoft.Web/sites/slots/host/functionKeys",
"apiVersion": "2020-12-01",
"name": "[concat(variables('func_name'),'/', variables('slot_name') ,'/default/default')]",
"properties": {
"name": "default",
"value": "[if(equals(parameters('env'),'dev'),parameters('devHostKey'),if(equals(parameters('env'),'acc'),parameters('accHostKey'),parameters('prdHostKey')))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites/slots', variables('func_name'),variables('slot_name'))]"
]
}
]
这样,我只需更改参数文件中的“env”参数,然后重新运行脚本,就可以将此插槽默认插槽主机密钥部署到我的所有环境。
希望这对将来的某人有所帮助:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.