{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "mysqladminID": { "minLength":1, "type": "string" }, "mysqladminPW": { "minLength":8, "maxLength":128, "type": "securestring" }, "skuName": { "defaultValue":"GP_Gen5_4", "type": "string" }, "skuSizeMB": { "defaultValue":51200, "type": "int" }, "skuTier": { "defaultValue":"GeneralPurpose", "type": "string" }, "version": { "defaultValue":"5.7", "type": "string" }, "virtualMachineSize": { "type": "string" }, "adminUsername": { "type": "string" }, "diskSizeGB": { "defaultValue":30, "type": "string" }, "adminPublicKey": { "type": "string" }, "addressPrefix": { "type": "string" }, "subnetPrefix": { "type": "string" }, "publicIpAddressType": { "type": "string" } }, "variables": { "serverName": "[toLower(concat(resourceGroup().name, 'mysql'))]", "virtualMachineName": "[concat(resourceGroup().name, 'vm')]", "virtualNetworkName": "[concat(resourceGroup().name, 'vnet')]", "networkInterfaceName": "[concat(resourceGroup().name, 'nic')]", "networkSecurityGroupName": "[concat(resourceGroup().name, 'nsg')]", "publicIpAddressName": "[concat(resourceGroup().name, 'pip')]", "subnetName": "[concat(resourceGroup().name, 'subnet')]", "vnetID": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]" }, "resources": [ { "apiVersion": "2017-12-01", "location": "[resourceGroup().location]", "name": "[variables('serverName')]", "properties": { "version": "[parameters('version')]", "administratorLogin": "[parameters('mysqladminID')]", "administratorLoginPassword": "[parameters('mysqladminPW')]", "storageProfile": { "backupRetentionDays": 7, "geoRedundantBackup": "Disabled", "storageMB": "[parameters('skuSizeMB')]" }, "sslEnforcement": "Enabled", "createMode": "Default" }, "sku": { "name": "[parameters('skuName')]", "tier": "[parameters('skuTier')]", "family": "Gen5" }, "type":"Microsoft.DBforMySQL/servers", "resources":[ { "name":"subnetendpoint", "type":"virtualNetworkRules", "apiVersion":"2017-12-01", "dependsOn":[ "[concat('Microsoft.DBforMySQL/servers/', variables('serverName'))]", "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" ], "location":"[resourceGroup().location]", "properties":{ "virtualNetworkSubnetId": "[variables('subnetRef')]", "ignoreMissingVnetServiceEndpoint": true } }, { "name":"wordpressdb", "type":"databases", "apiVersion":"2017-12-01", "dependsOn":[ "[concat('Microsoft.DBforMySQL/servers/', variables('serverName'))]" ], "properties":{ "charset":"utf8", "collation":"utf8_general_ci" } } ] }, { "name": "[variables('virtualMachineName')]", "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2017-03-30", "location": "[resourceGroup().location]", "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]" ], "properties": { "osProfile": { "computerName": "[variables('virtualMachineName')]", "adminUsername": "[parameters('adminUsername')]", "linuxConfiguration": { "disablePasswordAuthentication": true, "ssh": { "publicKeys": [ { "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", "keyData": "[parameters('adminPublicKey')]" } ] } } }, "hardwareProfile": { "vmSize": "[parameters('virtualMachineSize')]" }, "storageProfile": { "imageReference": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "16.04-LTS", "version": "latest" }, "osDisk": { "createOption": "FromImage", "diskSizeGB": "[parameters('diskSizeGB')]", "managedDisk": { "storageAccountType": "Premium_LRS" } }, "dataDisks": [] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" } ] } } }, { "name": "[concat(variables('virtualMachineName'),'/userscript')]", "type": "Microsoft.Compute/virtualMachines/extensions", "location": "[resourceGroup().location]", "apiVersion": "2015-06-15", "dependsOn": [ "[concat('Microsoft.Compute/virtualMachines/', variables('virtualMachineName'))]" ], "properties": { "publisher": "Microsoft.Azure.Extensions", "type": "CustomScript", "typeHandlerVersion": "2.0", "autoUpgradeMinorVersion": true, "settings": { "fileUris": [ "https://raw.githubusercontent.com/krazure/workshop-itpro-101/master/source/script/script.sh" ], "commandToExecute": "[concat('sh script.sh && sed -i -e \"s/username_here/wpsqladmin@', variables('serverName'), '/\" /var/www/html/wp-config.php && sed -i -e \"s/localhost/', variables('serverName'),'.mysql.database.azure.com/\" /var/www/html/wp-config.php')]" } } }, { "name": "[variables('virtualNetworkName')]", "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2017-08-01", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ "[parameters('addressPrefix')]" ] }, "subnets": [ { "name": "[variables('subnetName')]", "properties": { "addressPrefix": "[parameters('subnetPrefix')]", "serviceEndpoints": [ { "service": "Microsoft.Sql", "locations": [ "[resourceGroup().location]" ] } ] } } ] } }, { "name": "[variables('networkInterfaceName')]", "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2016-09-01", "location": "[resourceGroup().location]", "dependsOn": [ "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]", "[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]", "[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "subnet": { "id": "[variables('subnetRef')]" }, "privateIPAllocationMethod": "Dynamic", "publicIpAddress": { "id": "[resourceId(resourceGroup().name,'Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]" } } } ], "networkSecurityGroup": { "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" } } }, { "name": "[variables('publicIpAddressName')]", "type": "Microsoft.Network/publicIPAddresses", "apiVersion": "2017-08-01", "location": "[resourceGroup().location]", "properties": { "publicIPAllocationMethod": "[parameters('publicIpAddressType')]" }, "sku": { "name": "Basic" } }, { "name": "[variables('networkSecurityGroupName')]", "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "2017-06-01", "location": "[resourceGroup().location]", "properties": { "securityRules": [ { "name": "default-allow-ssh", "properties": { "priority": 1000, "protocol": "Tcp", "access": "Allow", "direction": "Inbound", "sourceAddressPrefix": "*", "sourcePortRange": "*", "destinationAddressPrefix": "*", "destinationPortRange": "22" } }, { "name": "default-allow-http", "properties": { "priority": 1100, "protocol": "Tcp", "access": "Allow", "direction": "Inbound", "sourceAddressPrefix": "*", "sourcePortRange": "*", "destinationAddressPrefix": "*", "destinationPortRange": "80" } }, { "name": "default-allow-docker", "properties": { "priority": 1200, "protocol": "Tcp", "access": "Allow", "direction": "Inbound", "sourceAddressPrefix": "*", "sourcePortRange": "*", "destinationAddressPrefix": "*", "destinationPortRange": "8080" } } ] } } ], "outputs": { "adminUsername": { "type": "string", "value": "[parameters('adminUsername')]" } } }