[英]How to add a default function key with ARM template for a deployment slot in Azure Functions
I want to add a default function key to my deployment slot in azure.我想在 azure 的部署槽中添加一个默认的 function 密钥。 Therefore I've added it to my template like this:因此,我将它添加到我的模板中,如下所示:
...,
{
"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"
}
},...
Unfortunately, I cannot find how to get it to work, this is the closest I can find to not have the template fail (fewer segments make the template invalid) Now I get this error:不幸的是,我找不到如何让它工作,这是我能找到的最接近模板失败的方法(更少的段使模板无效)现在我得到这个错误:
NotFound: Error creating or updating function key. 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? 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 ? I can get it to work for the production slot though:我可以让它为生产槽工作:
...,
{
"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"
}
},...
Any help is appreciated.任何帮助表示赞赏。
This worked for me.这对我有用。 I think you're missing the slot name in the name property:我认为您在 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')]"
]
},
I can't yet comment, so I am force to write an answer:-( I would like to add one small thing that I found super helpful when using the above answer. I expect that someone looking at this question might find it helpful to see this linked directly here.我还不能发表评论,所以我不得不写一个答案:-(我想添加一件我发现在使用上述答案时非常有用的小东西。我希望看到这个问题的人可能会发现它对在这里直接看到这个链接。
While trying to deploy multiple environments with one ARM template I used the above answer and extended it by creating one parameter per environment in the parameter file:在尝试使用一个 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": {..... }
}
Then in my ARM template I used然后在我使用的 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'))]"
]
}
]
This way I can deploy this slot default slot Host key to all my environments just by changing the "env" parameter in my parameter file, and then rerunning the script.这样,我只需更改参数文件中的“env”参数,然后重新运行脚本,就可以将此插槽默认插槽主机密钥部署到我的所有环境。
Hope this helps someone in the future:-)希望这对将来的某人有所帮助:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.