# ESXi

resource "esxi_guest" "main" {
  guest_name = "${var.prefix}-vm"
  disk_store = "datastore1"

  memsize  = "1024"
  numvcpus = "1"
  power    = "on"

  ovf_source = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
  network_interfaces {
    virtual_network = "VM Network"
  }
}

# Azure

resource "azurerm_virtual_network" "main" {
  name                = "${var.prefix}-network"
  address_space       = ["10.0.0.0/16"]
  location            = var.azure_location
  resource_group_name = var.azure_resourcegroup
}

resource "azurerm_subnet" "main" {
  name                 = "internal"
  resource_group_name  = var.azure_resourcegroup
  virtual_network_name = azurerm_virtual_network.main.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "main" {
  name                = "${var.prefix}-nic"
  location            = var.azure_location
  resource_group_name = var.azure_resourcegroup

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.main.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_linux_virtual_machine" "main" {
  name                = "${var.prefix}-vm"
  location            = var.azure_location
  resource_group_name = var.azure_resourcegroup
  network_interface_ids = [
    azurerm_network_interface.main.id,
  ]
  size = "Standard_B2ats_v2"

  admin_username = "adminuser"
  admin_ssh_key {
    username   = "adminuser"
    public_key = data.azurerm_ssh_public_key.azure.public_key
  }

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "ubuntu-24_04-lts"
    sku       = "server"
    version   = "latest"
  }
}
