我测试了您正在尝试的相同场景,即将资源组中的密钥库中的证书导入另一个资源组中的应用程序服务。
我使用下面的代码来做到这一点:
param name string
param location string = resourceGroup().location
param keyvaultid string
param certificatesecretname string
@secure()
param pass string
param exisitingappplanresourceid string
resource prodCertificate 'Microsoft.Web/certificates@2021-02-01' = {
name: name
location: location
properties: {
keyVaultId: keyvaultid
keyVaultSecretName: certificatesecretname
password: pass
serverFarmId: exisitingappplanresourceid
}
}
输出:
Keyvault 中的现有证书:
部署和参数:
Azure 门户应用服务:
注意:请确保必须Microsoft.Web Resource Provider
有权访问密钥库。您可以通过Keyvault>>access policies>>add a accesspolicy
进入abfa0a7c-a6b6-4736-8310-5855508787cd
服务主体搜索对话框从门户中执行此操作,以便它将以下资源提供者添加到访问策略中。
如果您想从 keyvault 添加证书,然后还创建一个 ssl 绑定,那么您可以使用如下所示的内容:
@description('Existing App Service Plan resource id that contains the App Service being updated')
param existingServerFarmId string
@description('User friendly certificate resource name')
param certificateName string
@description('Existing Key Vault resource Id with an access policy to allow Microsoft.Web RP to read Key Vault secrets (Checkout README.md for more information)')
param existingKeyVaultId string
@description('Key Vault Secret that contains a PFX certificate')
param existingKeyVaultSecretName string
@description('Existing App name to use for creating SSL binding. This App should have the hostname assigned as a custom domain')
param existingWebAppName string
@description('Custom hostname for creating SSL binding. This hostname should already be assigned to the Web App')
param hostname string
@description('Location for all resources.')
param location string = resourceGroup().location
resource certificateName_resource 'Microsoft.Web/certificates@2019-08-01' = {
name: certificateName
location: location
properties: {
keyVaultId: existingKeyVaultId
keyVaultSecretName: existingKeyVaultSecretName
serverFarmId: existingServerFarmId
}
}
resource existingWebAppName_resource 'Microsoft.Web/sites@2019-08-01' = {
name: existingWebAppName
location: location
properties: {
name: existingWebAppName
hostNameSslStates: [
{
name: hostname
sslState: 'SniEnabled'
thumbprint: certificateName_resource.properties.thumbprint
toUpdate: true
}
]
}
}
参考:
Microsoft.Web/certificates - Bicep & ARM 模板参考 | 微软文档