根据您的描述和屏幕截图,您希望将 UserAssigned Managed Identity 添加到您的 keyvault 以及它的创建中,并且 keyvault 和 Managed Identity 位于不同的资源组中。
如果是这样,accessPolicies
应该在下面,它在我这边工作正常。
"accessPolicies": [
{
"tenantId": "[subscription().tenantId]",
"objectId": "[reference(ResourceId(parameters('managedIdentityRG'), 'Microsoft.ManagedIdentity/userAssignedIdentities', parameters('managedIdentityName')),'2018-11-30','Full').properties.principalId]",
"permissions": {
"keys": [],
"secrets": [
"Get"
],
"certificates": []
}
}
]
我的完整模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaults_joykeyvault12_name": {
"type": "String"
},
"managedIdentityName": {
"type": "String"
},
"managedIdentityRG":{
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"name": "[parameters('vaults_joykeyvault12_name')]",
"location": "eastus",
"tags": {},
"properties": {
"sku": {
"family": "A",
"name": "Standard"
},
"tenantId": "[subscription().tenantId]",
"accessPolicies": [
{
"tenantId": "[subscription().tenantId]",
"objectId": "[reference(ResourceId(parameters('managedIdentityRG'), 'Microsoft.ManagedIdentity/userAssignedIdentities', parameters('managedIdentityName')),'2018-11-30','Full').properties.principalId]",
"permissions": {
"keys": [],
"secrets": [
"Get"
],
"certificates": []
}
}
],
"enabledForDeployment": false,
"enabledForDiskEncryption": false,
"enabledForTemplateDeployment": false,
"enableSoftDelete": true
}
}
]
}