Azure.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.17.1.54307",
      "templateHash": "4264810070198300748"
    }
  },
  "parameters": {
    "name": {
      "type": "string",
      "defaultValue": "xtec",
      "metadata": {
        "description": "The name of your virtual machine."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "westeurope",
      "metadata": {
        "description": "The datacenter location of your cluster."
      }
    },
    "size": {
      "type": "string",
      "defaultValue": "Standard_B1s",
      "metadata": {
        "description": "The size of your virtual machine."
      }
    },
    "username": {
      "type": "string",
      "defaultValue": "box"
    },
    "publicKey": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2022-11-01",
      "name": "[format('{0}-vnet', parameters('name'))]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.1.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "[format('{0}-vnet-1', parameters('name'))]",
            "properties": {
              "addressPrefix": "10.1.1.0/24"
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-11-01",
      "name": "[format('{0}-ip', parameters('name'))]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Basic"
      },
      "properties": {
        "publicIPAllocationMethod": "Dynamic",
        "publicIPAddressVersion": "IPv4"
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2023-03-01",
      "name": "[format('{0}-vm', parameters('name'))]",
      "location": "[parameters('location')]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('size')]"
        },
        "storageProfile": {
          "osDisk": {
            "createOption": "FromImage",
            "managedDisk": {
              "storageAccountType": "Standard_LRS"
            }
          },
          "imageReference": {
            "publisher": "Canonical",
            "offer": "0001-com-ubuntu-server-jammy",
            "sku": "22_04-lts-gen2",
            "version": "latest"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', format('{0}-nic', parameters('name')))]"
            }
          ]
        },
        "osProfile": {
          "computerName": "[parameters('name')]",
          "adminUsername": "[parameters('username')]",
          "linuxConfiguration": {
            "ssh": {
              "publicKeys": [
                {
                  "keyData": "[parameters('publicKey')]",
                  "path": "[format('/home/{0}/.ssh/authorized_keys', parameters('username'))]"
                }
              ]
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces', format('{0}-nic', parameters('name')))]"
      ]
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-11-01",
      "name": "[format('{0}-nic', parameters('name'))]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[reference(resourceId('Microsoft.Network/virtualNetworks', format('{0}-vnet', parameters('name'))), '2022-11-01').subnets[0].id]"
              },
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-ip', parameters('name')))]"
              }
            }
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}-ip', parameters('name')))]",
        "[resourceId('Microsoft.Network/virtualNetworks', format('{0}-vnet', parameters('name')))]"
      ]
    }
  ]
}