gpt4 book ai didi

json - Azure ARM 模板 - 在不同资源组的 Keyvault 中创建 KeyVault secret

转载 作者:行者123 更新时间:2023-12-05 01:40:50 27 4
gpt4 key购买 nike

我正在 Azure 中部署虚拟机。用户名和密码是自动创建的,并在部署时作为参数传递。部署虚拟机的资源组也作为参数传递,因此可以是任何内容。

我的Keyvault位于特定资源组中,虚拟机的用户名和密码应存储在此处。

当 Keyvault 与虚拟机位于同一资源组中时,它可以正常工作。但是当它位于不同的资源组中时,我收到以下错误:

"error": {
"code": "ParentResourceNotFound",
"message": "Can not perform requested operation on nested resource. Parent resource 'mykeyvault' not found."
}
} undefined

这是 ARM 模板的一部分,我在其中创建 secret 。

{
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[concat(variables('keyVaultName'), '/', variables('AdminUsername'))]",
"apiVersion": "2018-02-14",
"properties": {
"contentType": "Secret",
"value": "[variables('AdminUsername')]"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('VMName'))]"
]
},
{
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[concat(variables('keyVaultName'), '/', parameters('VMName'),'-AdminPassword')]",
"apiVersion": "2018-02-14",
"properties": {
"contentType": "Secret",
"value": "[parameters('AdminPassword')]"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('VMName'))]"
]
},

我还尝试将 keyVaultName 变量替换为 keyvault 的 ResourceID,但这会产生不同的错误“段长度不正确”

最佳答案

发生这种情况是因为 ARM 模板将资源部署到特定资源组。如果 KV 位于不同的资源组中,您需要使用嵌套部署并定位该资源组,如下所示:

{
"apiVersion": "2017-05-10",
"name": "nestedTemplate",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('kvResourceGroup')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('VMName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[format('{0}/{1}', variables('keyVaultName'), variables('AdminUsername'))]",
"apiVersion": "2018-02-14",
"properties": {
"contentType": "Secret",
"value": "[variables('AdminUsername')]"
}
},
{
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[format('{0}/{1}-AdminPassword', variables('keyVaultName'), parameters('VMName'))]",
"apiVersion": "2018-02-14",
"properties": {
"contentType": "Secret",
"value": "[parameters('AdminPassword')]"
}
}
]
}
}
},

关于json - Azure ARM 模板 - 在不同资源组的 Keyvault 中创建 KeyVault secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55742663/

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