Skip to content

Commit

Permalink
Adding MySQL Flexible Server (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldotyu authored Feb 5, 2023
1 parent ef6392e commit 63be196
Show file tree
Hide file tree
Showing 15 changed files with 395 additions and 766 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {
"version": "latest",
"installBicep": "true"
},
"ghcr.io/devcontainers/features/terraform:1": {},
"ghcr.io/devcontainers/features/dotnet:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"GitHub.copilot-labs",
"ms-azuretools.vscode-bicep"
]
}
}
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dotnetAcquisitionExtension.existingDotnetPath": [
"/usr/local/dotnet/current/dotnet"
]
}
134 changes: 60 additions & 74 deletions azuredeploy.bicep
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
param location string = resourceGroup().location

@description('Name of azure web app')
param siteName string

Expand Down Expand Up @@ -65,34 +67,23 @@ param skuName string = 'S1'
@minValue(1)
param skuCapacity int = 1

@description('Azure database for MySQL sku Size ')
param databaseSkuSizeMB int = 5120
@description('Initial MySQL database storage size in GB ')
param databaseStorageSizeGB int = 32

@description('Select MySql server performance tier. Please review https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers and ensure your choices are available in the selected region.')
@allowed([
'Basic'
'GeneralPurpose'
'MemoryOptimized'
])
param databaseForMySqlTier string = 'GeneralPurpose'
@description('Initial MySQL databse storage IOPS')
param databaseStorageIops int = 396

@description('Select MySql compute generation. Please review https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers and ensure your choices are available in the selected region.')
@allowed([
'Gen4'
'Gen5'
'Enabled'
'Disabled'
])
param databaseForMySqlFamily string = 'Gen5'
param databaseStorageAutoGrow string = 'Enabled'

@description('Select MySql vCore count. Please review https://docs.microsoft.com/en-us/azure/mysql/concepts-pricing-tiers and ensure your choices are available in the selected region.')
@allowed([
1
2
4
8
16
32
'Enabled'
'Disabled'
])
param databaseForMySqlCores int = 2
param databseStorageAutoIoScaling string = 'Enabled'

@description('MySQL version')
@allowed([
Expand Down Expand Up @@ -120,23 +111,17 @@ param repoURL string = 'https://github.com/microsoft/azure-redcap-paas.git'
@description('The main branch of the application repo')
param branch string = 'main'

var siteName_var = replace(siteName, ' ', '')
var databaseName = '${siteName_var}_db'
var serverName_var = '${siteName_var}${uniqueString(resourceGroup().id)}'
var hostingPlanName_var = '${siteName_var}_serviceplan'
var webSiteName_var = '${siteName_var}${uniqueString(resourceGroup().id)}'
var tierSymbol = {
Basic: 'B'
GeneralPurpose: 'GP'
MemoryOptimized: 'MO'
}
var databaseForMySqlSku = '${tierSymbol[databaseForMySqlTier]}_${databaseForMySqlFamily}_${databaseForMySqlCores}'
var storageName_var = 'storage${uniqueString(resourceGroup().id)}'
var storageAccountId = '${resourceGroup().id}/providers/Microsoft.Storage/storageAccounts/${storageName_var}'
var siteNameCleaned = replace(siteName, ' ', '')
var databaseName = '${siteNameCleaned}_db'
var uniqueServerName = '${siteNameCleaned}${uniqueString(resourceGroup().id)}'
var hostingPlanNameCleaned = '${siteNameCleaned}_serviceplan'
var uniqueWebSiteName = '${siteNameCleaned}${uniqueString(resourceGroup().id)}'
var uniqueStorageName = 'storage${uniqueString(resourceGroup().id)}'
var storageAccountId = '${resourceGroup().id}/providers/Microsoft.Storage/storageAccounts/${uniqueStorageName}'

resource storageName 'Microsoft.Storage/storageAccounts@2016-01-01' = {
name: storageName_var
location: resourceGroup().location
name: uniqueStorageName
location: location
sku: {
name: storageType
}
Expand All @@ -158,8 +143,8 @@ resource storageContainer 'Microsoft.Storage/storageAccounts/blobServices/contai
}

resource hostingPlanName 'Microsoft.Web/serverfarms@2016-09-01' = {
name: hostingPlanName_var
location: resourceGroup().location
name: hostingPlanNameCleaned
location: location
tags: {
displayName: 'HostingPlan'
}
Expand All @@ -169,30 +154,23 @@ resource hostingPlanName 'Microsoft.Web/serverfarms@2016-09-01' = {
}
kind: 'linux'
properties: {
name: hostingPlanName_var
name: hostingPlanNameCleaned
reserved: true
}
}

resource webSiteName 'Microsoft.Web/sites@2016-08-01' = {
name: webSiteName_var
location: resourceGroup().location
name: uniqueWebSiteName
location: location
tags: {
displayName: 'WebApp'
}
properties: {
name: webSiteName_var
serverFarmId: hostingPlanName_var
name: uniqueWebSiteName
serverFarmId: hostingPlanNameCleaned
siteConfig: {
linuxFxVersion: linuxFxVersion
alwaysOn: true
connectionStrings: [
{
name: 'defaultConnection'
connectionString: 'Database=${databaseName};Data Source=${serverName_var}.mysql.database.azure.com;User Id=${administratorLogin}@${serverName_var};Password=${administratorLoginPassword}'
type: 'MySql'
}
]
appCommandLine: '/home/startup.sh'
appSettings: [
{
Expand All @@ -201,7 +179,7 @@ resource webSiteName 'Microsoft.Web/sites@2016-08-01' = {
}
{
name: 'StorageAccount'
value: storageName_var
value: uniqueStorageName
}
{
name: 'StorageKey'
Expand All @@ -225,20 +203,24 @@ resource webSiteName 'Microsoft.Web/sites@2016-08-01' = {
}
{
name: 'DBHostName'
value: '${serverName_var}.mysql.database.azure.com'
value: '${uniqueServerName}.mysql.database.azure.com'
}
{
name: 'DBName'
value: databaseName
}
{
name: 'DBUserName'
value: '${administratorLogin}@${serverName_var}'
value: administratorLogin
}
{
name: 'DBPassword'
value: administratorLoginPassword
}
{
name: 'DBSslCa'
value: '/home/site/wwwroot/DigiCertGlobalRootCA.crt.pem'
}
{
name: 'PHP_INI_SCAN_DIR'
value: '/usr/local/etc/php/conf.d:/home/site'
Expand Down Expand Up @@ -279,7 +261,7 @@ resource webSiteName 'Microsoft.Web/sites@2016-08-01' = {
resource webSiteName_web 'Microsoft.Web/sites/sourcecontrols@2015-08-01' = {
parent: webSiteName
name: 'web'
location: resourceGroup().location
location: location
tags: {
displayName: 'CodeDeploy'
}
Expand All @@ -293,31 +275,39 @@ resource webSiteName_web 'Microsoft.Web/sites/sourcecontrols@2015-08-01' = {
]
}

resource serverName 'Microsoft.DBforMySQL/servers@2017-12-01-preview' = {
location: resourceGroup().location
name: serverName_var
resource serverName 'Microsoft.DBforMySQL/flexibleServers@2021-12-01-preview' = {
location: location
name: uniqueServerName
tags: {
displayName: 'MySQLAzure'
}
properties: {
version: mysqlVersion
administratorLogin: administratorLogin
administratorLoginPassword: administratorLoginPassword
storageProfile: {
storageMB: databaseSkuSizeMB
backupRetentionDays: '7'
storage: {
storageSizeGB: databaseStorageSizeGB
iops: databaseStorageIops
autoGrow: databaseStorageAutoGrow
autoIoScaling: databseStorageAutoIoScaling
}
backup: {
backupRetentionDays: 7
geoRedundantBackup: 'Disabled'
}
sslEnforcement: 'Disabled'
highAvailability: {
mode: 'Disabled'
}
replicationRole: 'None'
}
sku: {
name: databaseForMySqlSku
name: 'Standard_B1ms'
tier: 'Burstable'
}
}

resource serverName_AllowAzureIPs 'Microsoft.DBforMySQL/servers/firewallrules@2017-12-01-preview' = {
resource serverName_AllowAzureIPs 'Microsoft.DBforMySQL/flexibleServers/firewallRules@2021-12-01-preview' = {
parent: serverName
location: resourceGroup().location
name: 'AllowAzureIPs'
properties: {
startIpAddress: '0.0.0.0'
Expand All @@ -328,21 +318,17 @@ resource serverName_AllowAzureIPs 'Microsoft.DBforMySQL/servers/firewallrules@20
]
}

resource serverName_databaseName 'Microsoft.DBforMySQL/servers/databases@2017-12-01' = {
resource serverName_databaseName 'Microsoft.DBforMySQL/flexibleServers/databases@2021-12-01-preview' = {
parent: serverName
name: '${databaseName}'
tags: {
displayName: 'DB'
}
name: databaseName
properties: {
charset: 'utf8'
collation: 'utf8_general_ci'
}
}

output MySQLHostName string = '${serverName_var}.mysql.database.azure.com'
output MySqlUserName string = '${administratorLogin}@${serverName_var}'
output webSiteFQDN string = '${webSiteName_var}.azurewebsites.net'
output storageAccountKey string = concat(listKeys(storageAccountId, '2015-05-01-preview').key1)
output storageAccountName string = storageName_var
output MySQLHostName string = '${uniqueServerName}.mysql.database.azure.com'
output MySqlUserName string = '${administratorLogin}@${uniqueServerName}'
output webSiteFQDN string = '${uniqueWebSiteName}.azurewebsites.net'
output storageAccountName string = uniqueStorageName
output storageContainerName string = storageContainerName
Loading

0 comments on commit 63be196

Please sign in to comment.