Skip to content

Instantly share code, notes, and snippets.

@shashank-shekhar
Created June 22, 2024 02:29
Show Gist options
  • Save shashank-shekhar/4f4f01a3539f52f50adfebccfe683fe9 to your computer and use it in GitHub Desktop.
Save shashank-shekhar/4f4f01a3539f52f50adfebccfe683fe9 to your computer and use it in GitHub Desktop.
Bicep file to create azure resources
param location string = resourceGroup().location
param applicationSuffix string
param environment string
param resourceAbbreviations object
param sqlServerConfig object
param appServicePlanConfig object
param sqlDbConfig object
// Function to create resource names
@description('Creates a resource name based on the application suffix, environment, and resource abbreviation.')
func createResourceName(suffix string, env string, abbreviation string) string => '${suffix}-${env}-${abbreviation}'
// Create Azure storage account
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: toLower('${applicationSuffix}${environment}${resourceAbbreviations.storageAccount}')
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
// Create SQL server
resource sqlServer 'Microsoft.Sql/servers@2023-08-01-preview' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.sqlServer)
location: location
properties: {
administratorLogin: sqlServerConfig.adminLogin
administratorLoginPassword: sqlServerConfig.adminPassword
version: '12.0'
}
}
// Create SQL database
resource sqlDatabase 'Microsoft.Sql/servers/databases@2023-08-01-preview' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.sqlDatabase)
location: location
properties: {
collation: 'SQL_Latin1_General_CP1_CI_AS'
maxSizeBytes: 1073741824
}
sku: {
name: sqlDbConfig.sku.name
tier: sqlDbConfig.sku.tier
}
parent: sqlServer
}
// Create a vnet
resource vnet 'Microsoft.Network/virtualNetworks@2023-11-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.virtualNetwork)
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/16'
]
}
subnets: [
{
name: 'default'
properties: {
addressPrefix: '10.0.0.0/24'
}
}
{
name: 'AppServiceSubnet'
properties: {
addressPrefix: '10.0.1.0/24'
delegations: [
{
name: 'AppServiceDelegation'
properties: {
serviceName: 'Microsoft.Web/serverfarms'
}
}
]
}
}
{
name: 'SqlDbSubnet'
properties: {
addressPrefix: '10.0.2.0/24'
}
}
]
}
}
// Create a private endpoint
resource privateEndpoint 'Microsoft.Network/privateEndpoints@2023-11-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.privateEndpoint)
location: resourceGroup().location
properties: {
subnet: {
id: vnet.properties.subnets[2].id
}
privateLinkServiceConnections: [
{
name: 'myPrivateLinkServiceConnection'
properties: {
privateLinkServiceId: sqlServer.id
groupIds: [
'sqlServer'
]
}
}
]
}
}
// Create app service plan
resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.appServicePlan)
location: location
sku: {
tier: appServicePlanConfig.sku.tier
name: appServicePlanConfig.sku.name
}
}
// Create app service
resource appService 'Microsoft.Web/sites@2023-12-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.appService)
location: location
kind: 'app'
properties: {
serverFarmId: appServicePlan.id
virtualNetworkSubnetId: vnet.properties.subnets[1].id
}
}
// Create static web app
resource staticWebApp 'Microsoft.Web/staticSites@2021-02-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.staticApp)
location: location
properties:{allowConfigFileUpdates: true
repositoryUrl:''
}
sku: {
name: 'Free'
}
}
// Create a function app
resource functionApp 'Microsoft.Web/sites@2023-12-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.functions)
location: location
kind: 'functionapp'
properties: {
serverFarmId: appServicePlan.id
}
}
// Azure AI Services
resource azureAI 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.azureAIServices)
location: location
sku: {
name: 'S0'
}
kind: 'CognitiveServices'
properties: {
apiProperties: {
statisticsEnabled: true
}
restore: true
}
}
// Document Intelligence
resource documentIntelligence 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: createResourceName(applicationSuffix, environment, resourceAbbreviations.documentIntelligence)
location: location
sku: {
name: 'F0'
}
kind: 'FormRecognizer'
properties: {
apiProperties: {
statisticsEnabled: true
}
restore: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment