{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "admin-username": {
            "type": "string"
        },
        "ssh-public-key": {
            "type": "string"
        }    
    },
    "variables": {
        "ssh-keypath": "[concat('/home/', parameters('admin-username'), '/.ssh/authorized_keys')]",
        "unique-prefix": "[concat(replace(resourceGroup().name,'-',''), substring(uniquestring(resourceGroup().name), 0, 5))]",
        "storage-name": "[variables('unique-prefix')]",
        "vnet-name": "[concat(resourceGroup().name, '-vnet')]",
        "ip-prefix": "[concat(resourceGroup().name, '-ip-')]",
        "nsg-prefix": "[concat(resourceGroup().name, '-nsg-')]",
        "vm-prefix": "[concat(resourceGroup().name, '-vm-')]",
        "nic-prefix": "[concat(resourceGroup().name, '-nic-')]",            
        "names": [ "alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega" ],
        "vm-size": "Standard_DS1_v2",
        "vnet-address-space":  "10.16.0.0/12",
        "vnet-subnet01-octet": 17
    },
    "resources": [
        {
            "comments": "",
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[concat(variables('ip-prefix'), variables('names')[0])]",
            "apiVersion": "2017-03-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "publicIPAllocationMethod": "Dynamic",
                "idleTimeoutInMinutes": 4,
                "dnsSettings": {
                    "domainNameLabel": "[concat(variables('unique-prefix'), '-', variables('names')[0])]"
                }
            },
            "resources": [],
            "dependsOn": []
        },
        {
            "comments": "",
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[concat(variables('vm-prefix'), variables('names')[0])]",
            "apiVersion": "2016-04-30-preview",
            "location": "[resourceGroup().location]",
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[variables('vm-size')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "OpenLogic",
                        "offer": "CentOS",
                        "sku": "7.2",
                        "version": "latest"
                    },
                    "osDisk": {
                        "name": "[concat(variables('vm-prefix'), variables('names')[0], '-boot')]",
                        "createOption": "FromImage",
                        "vhd": {
                            "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storage-name')), '2015-06-15').primaryEndpoints.blob, 'vhds/', variables('names')[0], '-boot.vhd')]"
                        },
                        "caching": "ReadWrite"
                    },
                    "dataDisks": [
                        {
                          "name": "[concat(variables('vm-prefix'), variables('names')[0], '-disk01')]",
                          "diskSizeGB": 127,
                          "lun": 0,
                          "vhd": {
                              "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storage-name')), '2015-06-15').primaryEndpoints.blob, 'vhds/', variables('names')[0], '-data01.vhd')]"
                          },
                          "createOption": "Empty"
                        }
                    ]
                },
                "osProfile": {
                    "computerName": "[concat(variables('vm-prefix'), variables('names')[0])]",
                    "adminUsername": "[parameters('admin-username')]",
                    "linuxConfiguration": {
                        "disablePasswordAuthentication": true,
                        "ssh": {
                            "publicKeys": [
                                {
                                  "path": "[variables('ssh-keypath')]",
                                  "keyData": "[parameters('ssh-public-key')]"
                                }
                            ]
                        }
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nic-prefix'), variables('names')[0]))]"
                        }
                    ]
                }
            },
            "resources": [],
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storage-name'))]",
                "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nic-prefix'), variables('names')[0]))]"
            ]
        },
        {
            "comments": "",
            "type": "Microsoft.Network/networkInterfaces",
            "name": "[concat(variables('nic-prefix'), variables('names')[0])]",
            "apiVersion": "2017-03-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ifconfig1",
                        "properties": {
                            "privateIPAllocationMethod":"Dynamic",
                            "publicIPAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('ip-prefix'), variables('names')[0]))]"
                            },
                            "subnet": {
                                "id": "[concat(resourceId('Microsoft.Network/virtualNetworks', variables('vnet-name')), '/subnets/subnet01')]"
                            }
                        }
                    }
                ],
                "dnsSettings": {
                    "dnsServers": []
                },
                "enableIPForwarding": false,
                "networkSecurityGroup": {
                    "id": "[resourceId('Microsoft.Network/networkSecurityGroups', concat(variables('nsg-prefix'), variables('names')[0]))]"
                }
            },
            "resources": [],
            "dependsOn": [
                "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('ip-prefix'), variables('names')[0]))]",
                "[resourceId('Microsoft.Network/virtualNetworks', variables('vnet-name'))]",
                "[resourceId('Microsoft.Network/networkSecurityGroups', concat(variables('nsg-prefix'), variables('names')[0]))]"
            ]
        },
        {
            "comments": "",
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[variables('vnet-name')]",
            "apiVersion": "2017-03-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[variables('vnet-address-space')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "subnet01",
                        "properties": {
                            "addressPrefix": "[concat('10.', variables('vnet-subnet01-octet'), '.0.0/16')]"
                        }
                    }
                ]
            },
            "resources": [],
            "dependsOn": []
        },
        {
            "comments": "",
            "type": "Microsoft.Network/networkSecurityGroups",
            "name": "[concat(variables('nsg-prefix'), variables('names')[0])]",
            "apiVersion": "2017-03-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "securityRules": [
                    {
                        "name": "default-allow-ssh",
                        "properties": {
                            "protocol": "Tcp",
                            "sourcePortRange": "*",
                            "destinationPortRange": "22",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 1000,
                            "direction": "Inbound"
                        }
                    }
                ]
            },
            "resources": [],
            "dependsOn": []
        },
        {
            "comments": "",
            "type": "Microsoft.Storage/storageAccounts",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            },
            "kind": "Storage",
            "name": "[variables('storage-name')]",
            "apiVersion": "2016-01-01",
            "location": "[resourceGroup().location]",
            "tags": {},
            "properties": { },
            "resources": [],
            "dependsOn": []
        }
    ],
    "outputs": {
        "sshCommand": {
            "type": "string",
            "value": "[concat('ssh ', variables('unique-prefix'), '-', variables('names')[0], '.', resourceGroup().location, '.cloudapp.azure.com')]"
        }
    }
}

