ipam/deploy/main.bicep

151 строка
4.4 KiB
Bicep
Исходник Обычный вид История

2022-05-19 12:29:59 +03:00
// Global parameters
targetScope = 'subscription'
@description('GUID for Resource Naming')
param guid string = newGuid()
@description('Deployment Location')
param location string = deployment().location
@description('Prefix for Resource Naming')
param namePrefix string = 'ipam'
2022-05-25 00:56:22 +03:00
2022-08-10 11:18:49 +03:00
@description('Azure Cloud Enviroment')
param azureCloud string = 'AZURE_PUBLIC'
@description('Flag to Deploy IPAM as a Function')
param deployAsFunc bool = false
@description('IPAM-UI App Registration Client/App ID')
param uiAppId string = '00000000-0000-0000-0000-000000000000'
@description('IPAM-Engine App Registration Client/App ID')
param engineAppId string
2022-05-19 12:29:59 +03:00
@secure()
@description('IPAM-Engine App Registration Client Secret')
param engineAppSecret string
2022-05-19 12:29:59 +03:00
2022-05-25 00:56:22 +03:00
@description('Tags')
param tags object = {}
2022-05-19 12:29:59 +03:00
2022-05-25 00:56:22 +03:00
// Resource naming variables
var appServiceName = '${namePrefix}-${uniqueString(guid)}'
var appServicePlanName = '${namePrefix}-asp-${uniqueString(guid)}'
var cosmosAccountName = '${namePrefix}-dbacct-${uniqueString(guid)}'
var cosmosContainerName = '${namePrefix}-ctr'
var cosmosDatabaseName = '${namePrefix}-db'
2022-05-25 00:56:22 +03:00
var keyVaultName = '${namePrefix}-kv-${uniqueString(guid)}'
var workspaceName = '${namePrefix}-law-${uniqueString(guid)}'
2022-05-25 00:56:22 +03:00
var managedIdentityName = '${namePrefix}-mi-${uniqueString(guid)}'
var resourceGroupName = '${namePrefix}-rg-${uniqueString(guid)}'
var storageName = '${namePrefix}stg${uniqueString(guid)}'
2022-05-19 12:29:59 +03:00
// Resource Group
2022-05-19 12:29:59 +03:00
resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
location: location
2022-05-25 00:56:22 +03:00
name: resourceGroupName
tags: tags
2022-05-19 12:29:59 +03:00
}
// Log Analytics Workspace
module logAnalyticsWorkspace 'logAnalyticsWorkspace.bicep' ={
name: 'logAnalyticsWorkspaceModule'
scope: resourceGroup
params: {
workspaceName: workspaceName
location: location
}
}
// Managed Identity for Secure Access to KeyVault
2022-05-19 12:29:59 +03:00
module managedIdentity 'managedIdentity.bicep' = {
name: 'managedIdentityModule'
scope: resourceGroup
params: {
managedIdentityName: managedIdentityName
location: location
}
}
// KeyVault for Secure Values
module keyVault 'keyVault.bicep' = {
2022-05-19 12:29:59 +03:00
name: 'keyVaultModule'
scope: resourceGroup
params: {
keyVaultName: keyVaultName
location: location
principalId: managedIdentity.outputs.principalId
uiAppId: uiAppId
engineAppId: engineAppId
engineAppSecret: engineAppSecret
workspaceId: logAnalyticsWorkspace.outputs.workspaceId
2022-05-19 12:29:59 +03:00
}
}
// Cosmos DB for IPAM Database
2022-05-19 12:29:59 +03:00
module cosmos 'cosmos.bicep' = {
name: 'cosmosModule'
scope: resourceGroup
params: {
location: location
cosmosAccountName: cosmosAccountName
cosmosContainerName: cosmosContainerName
cosmosDatabaseName: cosmosDatabaseName
2022-05-19 12:29:59 +03:00
keyVaultName: keyVault.outputs.keyVaultName
workspaceId: logAnalyticsWorkspace.outputs.workspaceId
2022-05-19 12:29:59 +03:00
}
}
// Storage Account for Nginx Config
module storageAccount 'storageAccount.bicep' = {
scope: resourceGroup
name: 'storageAccountModule'
params: {
location: location
storageAccountName: storageName
principalId: managedIdentity.outputs.principalId
managedIdentityId: managedIdentity.outputs.id
workspaceId: logAnalyticsWorkspace.outputs.workspaceId
deployAsFunc: deployAsFunc
}
}
// App Service w/ Docker Compose + CI
module appService 'appService.bicep' = if (!deployAsFunc) {
2022-05-19 12:29:59 +03:00
scope: resourceGroup
name: 'appServiceModule'
params: {
location: location
2022-08-10 11:18:49 +03:00
azureCloud: azureCloud
2022-05-19 12:29:59 +03:00
appServicePlanName: appServicePlanName
appServiceName: appServiceName
keyVaultUri: keyVault.outputs.keyVaultUri
cosmosDbUri: cosmos.outputs.cosmosDocumentEndpoint
managedIdentityId: managedIdentity.outputs.id
storageAccountName: storageAccount.outputs.name
workspaceId: logAnalyticsWorkspace.outputs.workspaceId
2022-05-19 12:29:59 +03:00
}
}
// Function App
module functionApp 'functionApp.bicep' = if (deployAsFunc) {
scope: resourceGroup
name: 'functionAppModule'
params: {
location: location
2022-08-10 11:18:49 +03:00
azureCloud: azureCloud
functionAppPlanName: appServicePlanName
functionAppName: appServiceName
keyVaultUri: keyVault.outputs.keyVaultUri
cosmosDbUri: cosmos.outputs.cosmosDocumentEndpoint
managedIdentityId: managedIdentity.outputs.id
storageAccountName: storageAccount.outputs.name
workspaceId: logAnalyticsWorkspace.outputs.workspaceId
}
}
// Outputs
output appServiceHostName string = deployAsFunc ? functionApp.outputs.functionAppHostName : appService.outputs.appServiceHostName