How could I create a new API manager, then assign a role to access certificates of Azure Key Vault and create the hostnameConfigurations with the certification source inside Azure Key Vault.
I’ve tried something like this below but then I got next error message:
Deployment template validation failed: ‘The resource
Microsoft.ApiManagement/service/<apimname>
at line ‘1’ and column ‘2581’ is defined multiple times in a template. Please see https://aka.ms/arm-syntax-resources for usage details.’.
resource apim 'Microsoft.ApiManagement/service@2023-09-01-preview' = {
name: variables.resources.apim.name
sku: variables.resources.apim.sku
location: resourceGroup().location
properties: {
publisherEmail: variables.resources.apim.publisher.email
publisherName: variables.resources.apim.publisher.name
}
identity: {
type: 'SystemAssigned'
}
}
resource keyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = {
name: variables.resources.keyVault.name
}
resource apiKeyVaultRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: keyVault
name: guid(keyVault.id, apim.id, variables.rbac.keyVaultCertificateUser)
properties: {
roleDefinitionId: subscriptionResourceId(
'Microsoft.Authorization/roleDefinitions',
variables.rbac.keyVaultCertificateUser
)
principalId: apim.identity.principalId
principalType: 'ServicePrincipal'
}
}
resource apim 'Microsoft.ApiManagement/service@2023-09-01-preview' = {
name: variables.resources.apim.name
sku: variables.resources.apim.sku
location: resourceGroup().location
properties: {
publisherEmail: variables.resources.apim.publisher.email
publisherName: variables.resources.apim.publisher.name
hostnameConfigurations: [
{
type: 'Proxy'
hostName: variables.resources.apim.hostName
certificateSource: 'KeyVault'
defaultSslBinding: true
keyVaultId: 'https://${variables.resources.keyVault.name}.${az.environment().suffixes.keyvaultDns}/secrets/savaco-dns'
}
]
}
}