-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webapp-managed-mysql example (#1305)
- Loading branch information
Showing
3 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
param websiteName string | ||
param dbAdminLogin string | ||
param dbAdminPassword string { | ||
secure: true | ||
minLength: 8 | ||
maxLength: 128 | ||
} | ||
param dbSkuCapacity int { | ||
default: 2 | ||
allowed: [ | ||
2 | ||
4 | ||
8 | ||
16 | ||
32 | ||
] | ||
} | ||
param dbSkuName string { | ||
default: 'GP_Gen5_2' | ||
allowed: [ | ||
'GP_Gen5_2' | ||
'GP_Gen5_4' | ||
'GP_Gen5_8' | ||
'GP_Gen5_16' | ||
'GP_Gen5_32' | ||
'MO_Gen5_2' | ||
'MO_Gen5_4' | ||
'MO_Gen5_8' | ||
'MO_Gen5_16' | ||
'MO_Gen5_32' | ||
] | ||
} | ||
param dbSkuSizeInMB int { | ||
default: 51200 | ||
allowed: [ | ||
51200 | ||
102400 | ||
] | ||
} | ||
param dbSkuTier string { | ||
default: 'GeneralPurpose' | ||
allowed: [ | ||
'GeneralPurpose' | ||
'MemoryOptimized' | ||
] | ||
} | ||
param dbSkuFamily string = 'Gen5' | ||
param mySQLVersion string { | ||
allowed: [ | ||
'5.6' | ||
'5.7' | ||
] | ||
} | ||
param location string = resourceGroup().location | ||
|
||
var dbName = '${websiteName}-db' | ||
var dbServerName = '${websiteName}-server' | ||
var serverFarmName = '${websiteName}-serviceplan' | ||
|
||
resource serverFarm 'Microsoft.Web/serverfarms@2020-06-01' = { | ||
name: serverFarmName | ||
location: location | ||
sku: { | ||
tier: 'Standard' | ||
name: 'S1' | ||
} | ||
} | ||
resource website 'Microsoft.Web/sites@2020-06-01' = { | ||
name: websiteName | ||
location: location | ||
properties: { | ||
serverFarmId: serverFarm.id | ||
} | ||
} | ||
resource connectionString 'Microsoft.Web/sites/config@2020-06-01' = { | ||
name: '${website.name}/connectionString' | ||
properties: { | ||
defaultConnection: { | ||
value: 'Database=${dbName};Data Source=${dbServer.properties.fullyQualifiedDomainName};User Id=${dbAdminLogin}@${dbServer.name};Password=${dbAdminPassword}' | ||
type: 'MySql' | ||
} | ||
} | ||
} | ||
resource dbServer 'Microsoft.DBForMySQL/servers@2017-12-01-preview' = { | ||
name: dbServerName | ||
location: location | ||
sku: { | ||
name: dbSkuName | ||
tier: dbSkuTier | ||
capacity: dbSkuCapacity | ||
size: string(dbSkuSizeInMB) | ||
family: dbSkuFamily | ||
} | ||
properties: { | ||
createMode: 'Default' | ||
version: mySQLVersion | ||
administratorLogin: dbAdminLogin | ||
administratorLoginPassword: dbAdminPassword | ||
storageProfile: { | ||
storageMB: dbSkuSizeInMB | ||
backupRetentionDays: 7 | ||
geoRedundantBackup: 'Disabled' | ||
} | ||
sslEnforcement: 'Disabled' | ||
} | ||
} | ||
resource firewallRules 'Microsoft.DBForMySQL/servers/firewallRules@2017-12-01-preview' = { | ||
name: '${dbServer.name}/allowAzureIPs' | ||
properties: { | ||
startIpAddress: '0.0.0.0' | ||
endIpAddress: '0.0.0.0' | ||
} | ||
} | ||
resource database 'Microsoft.DBForMySQL/servers/databases@2017-12-01-preview' = { | ||
name: '${dbServer.name}/${dbName}' | ||
properties: { | ||
charset: 'utf8' | ||
collation: 'utf8_general_ci' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"websiteName": { | ||
"type": "string" | ||
}, | ||
"dbAdminLogin": { | ||
"type": "string" | ||
}, | ||
"dbAdminPassword": { | ||
"type": "secureString", | ||
"minLength": 8, | ||
"maxLength": 128 | ||
}, | ||
"dbSkuCapacity": { | ||
"type": "int", | ||
"defaultValue": 2, | ||
"allowedValues": [ | ||
2, | ||
4, | ||
8, | ||
16, | ||
32 | ||
] | ||
}, | ||
"dbSkuName": { | ||
"type": "string", | ||
"defaultValue": "GP_Gen5_2", | ||
"allowedValues": [ | ||
"GP_Gen5_2", | ||
"GP_Gen5_4", | ||
"GP_Gen5_8", | ||
"GP_Gen5_16", | ||
"GP_Gen5_32", | ||
"MO_Gen5_2", | ||
"MO_Gen5_4", | ||
"MO_Gen5_8", | ||
"MO_Gen5_16", | ||
"MO_Gen5_32" | ||
] | ||
}, | ||
"dbSkuSizeInMB": { | ||
"type": "int", | ||
"defaultValue": 51200, | ||
"allowedValues": [ | ||
51200, | ||
102400 | ||
] | ||
}, | ||
"dbSkuTier": { | ||
"type": "string", | ||
"defaultValue": "GeneralPurpose", | ||
"allowedValues": [ | ||
"GeneralPurpose", | ||
"MemoryOptimized" | ||
] | ||
}, | ||
"dbSkuFamily": { | ||
"type": "string", | ||
"defaultValue": "Gen5" | ||
}, | ||
"mySQLVersion": { | ||
"type": "string", | ||
"allowedValues": [ | ||
"5.6", | ||
"5.7" | ||
] | ||
}, | ||
"location": { | ||
"type": "string", | ||
"defaultValue": "[resourceGroup().location]" | ||
} | ||
}, | ||
"functions": [], | ||
"variables": { | ||
"dbName": "[format('{0}-db', parameters('websiteName'))]", | ||
"dbServerName": "[format('{0}-server', parameters('websiteName'))]", | ||
"serverFarmName": "[format('{0}-serviceplan', parameters('websiteName'))]" | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Web/serverfarms", | ||
"apiVersion": "2020-06-01", | ||
"name": "[variables('serverFarmName')]", | ||
"location": "[parameters('location')]", | ||
"sku": { | ||
"tier": "Standard", | ||
"name": "S1" | ||
} | ||
}, | ||
{ | ||
"type": "Microsoft.Web/sites", | ||
"apiVersion": "2020-06-01", | ||
"name": "[parameters('websiteName')]", | ||
"location": "[parameters('location')]", | ||
"properties": { | ||
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('serverFarmName'))]" | ||
}, | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Web/serverfarms', variables('serverFarmName'))]" | ||
] | ||
}, | ||
{ | ||
"type": "Microsoft.Web/sites/config", | ||
"apiVersion": "2020-06-01", | ||
"name": "[format('{0}/connectionString', parameters('websiteName'))]", | ||
"properties": { | ||
"defaultConnection": { | ||
"value": "[format('Database={0};Data Source={1};User Id={2}@{3};Password={4}', variables('dbName'), reference(resourceId('Microsoft.DBForMySQL/servers', variables('dbServerName'))).fullyQualifiedDomainName, parameters('dbAdminLogin'), variables('dbServerName'), parameters('dbAdminPassword'))]", | ||
"type": "MySql" | ||
} | ||
}, | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.DBForMySQL/servers', variables('dbServerName'))]", | ||
"[resourceId('Microsoft.Web/sites', parameters('websiteName'))]" | ||
] | ||
}, | ||
{ | ||
"type": "Microsoft.DBForMySQL/servers", | ||
"apiVersion": "2017-12-01-preview", | ||
"name": "[variables('dbServerName')]", | ||
"location": "[parameters('location')]", | ||
"sku": { | ||
"name": "[parameters('dbSkuName')]", | ||
"tier": "[parameters('dbSkuTier')]", | ||
"capacity": "[parameters('dbSkuCapacity')]", | ||
"size": "[string(parameters('dbSkuSizeInMB'))]", | ||
"family": "[parameters('dbSkuFamily')]" | ||
}, | ||
"properties": { | ||
"createMode": "Default", | ||
"version": "[parameters('mySQLVersion')]", | ||
"administratorLogin": "[parameters('dbAdminLogin')]", | ||
"administratorLoginPassword": "[parameters('dbAdminPassword')]", | ||
"storageProfile": { | ||
"storageMB": "[parameters('dbSkuSizeInMB')]", | ||
"backupRetentionDays": 7, | ||
"geoRedundantBackup": "Disabled" | ||
}, | ||
"sslEnforcement": "Disabled" | ||
} | ||
}, | ||
{ | ||
"type": "Microsoft.DBForMySQL/servers/firewallRules", | ||
"apiVersion": "2017-12-01-preview", | ||
"name": "[format('{0}/allowAzureIPs', variables('dbServerName'))]", | ||
"properties": { | ||
"startIpAddress": "0.0.0.0", | ||
"endIpAddress": "0.0.0.0" | ||
}, | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.DBForMySQL/servers', variables('dbServerName'))]" | ||
] | ||
}, | ||
{ | ||
"type": "Microsoft.DBForMySQL/servers/databases", | ||
"apiVersion": "2017-12-01-preview", | ||
"name": "[format('{0}/{1}', variables('dbServerName'), variables('dbName'))]", | ||
"properties": { | ||
"charset": "utf8", | ||
"collation": "utf8_general_ci" | ||
}, | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.DBForMySQL/servers', variables('dbServerName'))]" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters