{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "projectName": { "type": "string" }, "location": { "type": "string", "defaultValue": "francecentral" }, "adminUsername": { "type": "string", "defaultValue": "usernamevm" }, "adminPublicKey": { "type": "string", "defaultValue": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCx....." }, "vmSize": { "type": "string" }, "autoShutdownStatus": { "type": "string", "defaultValue": "Enabled" }, "autoShutdownTime": { "type": "string", "defaultValue": "19:00" }, "autoShutdownTimeZone": { "type": "string", "defaultValue": "UTC" }, "autoShutdownNotificationStatus": { "type": "string", "defaultValue": "Disabled" }, "autoShutdownNotificationLocale": { "type": "string", "defaultValue": "en" }, "storageAccountName": { "type": "string", "defaultValue": "saname" }, "storageAccountSkuName": { "type": "string", "defaultValue": "Standard_LRS" }, "storageAccountSkuType": { "type": "string", "defaultValue": "Standard" }, "storageAccountKind": { "type": "string", "defaultValue": "StorageV2" }, "extendedVM": { "type": "bool", "defaultValue": false }, "storageDataDiskSize": { "type": "string", "defaultValue": "1" } }, "variables": { "vNetName": "[concat('rg-projet', '-vnet')]", "vNetAddressPrefixes": "10.0.0.0/16", "vNetSubnetName": "default", "vNetSubnetAddressPrefix": "10.0.0.0/24", "vmName": "[concat(parameters('projectName'))]", "publicIPAddressName": "[concat(parameters('projectName'), '-ip')]", "networkInterfaceName": "[concat(parameters('projectName'), '961')]", "networkSecurityGroupName": "[concat(parameters('projectName'), '-nsg')]", "dataDisks": [ { "diskSizeGB": "[parameters('storageDataDiskSize')]", "lun": 0, "createOption": "Empty" } ] }, "resources": [ { "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "2020-05-01", "name": "[variables('networkSecurityGroupName')]", "location": "[parameters('location')]", "properties": { "securityRules": [ { "name": "SSH", "properties": { "priority": 300, "protocol": "TCP", "access": "Allow", "direction": "Inbound", "sourceAddressPrefix": "*", "sourcePortRange": "*", "destinationAddressPrefix": "*", "destinationPortRange": "22" } } ] } }, { "type": "Microsoft.Network/publicIPAddresses", "apiVersion": "2020-05-01", "name": "[variables('publicIPAddressName')]", "location": "[parameters('location')]", "properties": { "publicIPAllocationMethod": "Dynamic" }, "sku": { "name": "Basic" } }, { "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2020-05-01", "name": "[variables('vNetName')]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" ], "properties": { "addressSpace": { "addressPrefixes": [ "[variables('vNetAddressPrefixes')]" ] }, "subnets": [ { "name": "[variables('vNetSubnetName')]", "properties": { "addressPrefix": "[variables('vNetSubnetAddressPrefix')]", "networkSecurityGroup": { "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" } } } ] } }, { "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2020-05-01", "name": "[variables('networkInterfaceName')]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]", "[resourceId('Microsoft.Network/virtualNetworks', variables('vNetName'))]", "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" }, "subnet": { "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]" } } } ] } }, { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-06-01", "name": "[parameters('storageAccountName')]", "location": "[parameters('location')]", "sku": { "name": "[parameters('storageAccountSkuName')]", "tier": "[parameters('storageAccountSkuType')]" }, "kind": "[parameters('storageAccountKind')]", "properties": {} }, { "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2021-07-01", "name": "[variables('vmName')]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]", "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]" ], "properties": { "hardwareProfile": { "vmSize": "[parameters('vmSize')]" }, "osProfile": { "computerName": "[variables('vmName')]", "adminUsername": "[parameters('adminUsername')]", "linuxConfiguration": { "disablePasswordAuthentication": true, "ssh": { "publicKeys": [ { "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", "keyData": "[parameters('adminPublicKey')]" } ] } } }, "storageProfile": { "imageReference": { "publisher": "canonical", "offer": "0001-com-ubuntu-server-focal", "sku": "20_04-lts", "version": "latest" }, "osDisk": { "createOption": "FromImage" }, "dataDisks": "[if(bool(parameters('extendedVM')), variables('dataDisks'), json('null'))]" }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" } ] } } }, { "name": "[concat('shutdown-computevm-', variables('vmName'))]", "type": "Microsoft.DevTestLab/schedules", "apiVersion": "2018-09-15", "location": "[parameters('location')]", "dependsOn": [ "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" ], "properties": { "status": "[parameters('autoShutdownStatus')]", "taskType": "ComputeVmShutdownTask", "dailyRecurrence": { "time": "[parameters('autoShutdownTime')]" }, "timeZoneId": "[parameters('autoShutdownTimeZone')]", "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]", "notificationSettings": { "status": "[parameters('autoShutdownNotificationStatus')]", "notificationLocale": "[parameters('autoShutdownNotificationLocale')]", "timeInMinutes": "30" } } } ] }