ofvp_Server/deploys/AzureVm.json
2021-12-10 13:16:41 -03:00

202 lines
6.7 KiB
JSON

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the VM. This value is ignored."
},
"defaultValue": "ofvpuser"
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_B1s",
"metadata": {
"description": "Choose a machine in the size you need"
}
},
"IpType": {
"type": "string",
"defaultValue": "Static",
"allowedValues": [
"Dynamic",
"Static"
],
"metadata": {
"description": "Static ips, are ips that will be reserved if you turn off the vm, the dynamic ips are those after you turn off the machine, next time it will give you a new ip. Plus all of them will receive a fqdn from microsoft in case they want to add as CNAME in the DNS records."
}
},
"DockerTag": {
"type": "string",
"defaultValue": "latest",
"allowedValues": [
"latest",
"nightly"
],
"metadata": {
"description": "Release of the docker image to use"
}
},
"AutoUpdate": {
"type": "string",
"defaultValue": "true",
"allowedValues": [
"true",
"false"
],
"metadata": {
"description": "Release of the docker image to use"
}
},
"AutoUpdateCron": {
"type": "string",
"defaultValue": "0 0 * */7 *",
"metadata": {
"description": "Cron expression to use for the auto update"
}
}
},
"variables": {
"vmnamemain": "ofvp-server",
"cloud_init": "#cloud-config\n\nruncmd:\n- r=60 && ",
"nicName": "[concat(replace(replace(variables('vmNamemain'),'.',''),'_','-'), '-nic')]",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"storageAccountType": "Premium_LRS",
"storageAccountName": "[concat(uniqueString(replace(replace(replace(variables('vmNamemain'),'.',''),'_',''),'-',''), resourceGroup().id), 'data')]",
"publicIPAddressName": "[concat(replace(replace(variables('vmNamemain'),'.',''),'_','-'), '-pub-ip')]",
"dnsNameForPublicIP": "[concat(uniqueString(variables('vmNamemain'), resourceGroup().id), '-ofvp')]",
"vmName": "[concat(replace(replace(variables('vmNamemain'),'.',''),'_','-'), '-ofvp-vm')]",
"virtualNetworkName": "[concat(replace(replace(variables('vmNamemain'),'.',''),'_','-'), '-vnet')]",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]",
"InstallVariables": "[concat('docketag=\"', parameters('DockerTag'), '\" autoupdate=\"', parameters('AutoUpdate'), '\" autoupdatecron=\"', parameters('AutoUpdateCron'), '\"')]",
"CustomData": "[concat(variables('cloud_init'), 'curl https://raw.githubusercontent.com/OFVp-Project/Server/main/deploys/AzureVm.sh | sudo ', variables('InstallVariables'), ' bash -')]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2019-06-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "[variables('storageAccountType')]"
},
"kind": "StorageV2"
},
{
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "[parameters('IpType')]",
"dnsSettings": {
"domainNameLabel": "[variables('dnsNameForPublicIP')]"
}
}
},
{
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"apiVersion": "2020-05-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2021-07-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"customData": "[base64(variables('CustomData'))]"
},
"storageProfile": {
"imageReference": {
"publisher": "canonical",
"offer": "0001-com-ubuntu-server-focal",
"sku": "20_04-lts-gen2",
"version": "latest"
},
"osDisk": {
"name": "UbuntuDisk",
"caching": "ReadWrite",
"createOption": "FromImage",
"diskSizeGB": 128
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
}
}
}
],
"outputs": {
"user_script": {
"type": "string",
"value": "[variables('CustomData')]"
}
}
}