
terraform {
  required_providers {
    ionoscloud = {
      source = "registry.terraform.io/ionos-cloud/ionoscloud"
      version = "6.7.0"
    }
  }
}

data "ionoscloud_image" "simpl_vm" {
  type        = "HDD"
  cloud_init  = "V1"
  image_alias = "Ubuntu-22.04"
  location    = "eua"
}

resource "ionoscloud_datacenter" "simpl_vm" {
  name                = "ovh_2"
  location            = "eua"
  description         = "var.simpl_datacenter_description"
  sec_auth_protection = false
}

resource "ionoscloud_lan" "simpl_vm" {
  datacenter_id = ionoscloud_datacenter.simpl_vm.id
  public        = true
  name          = "simpl_vm_lan"
}

resource "ionoscloud_ipblock" "simpl_vm" {
  location = ionoscloud_datacenter.simpl_vm.location
  size     = 1
  name     = "ovh_2"
}

resource "ionoscloud_server" "simpl_vm" {
  name              = "simpl_vm_server"
  datacenter_id     = ionoscloud_datacenter.simpl_vm.id
  cores             = 2
  ram               = 2048
  availability_zone = "AUTO"
  cpu_family        = "INTEL_XEON"
  image_name        = data.ionoscloud_image.simpl_vm.name
  image_password    = "test1234"
  type              = "ENTERPRISE"

  volume {
    name              = "volume"
    size              = 100
    disk_type         = "SSD Standard"
    bus               = "VIRTIO"
    availability_zone = "AUTO"
    user_data         = "var.simpl_cloud_init"
  }

  nic {
    lan   = ionoscloud_lan.simpl_vm.id
    name  = "nic"
    dhcp  = true
    ips   = [ionoscloud_ipblock.simpl_vm.ips[0]]
  }
}

output "vmIps" {
  value = ionoscloud_server.simpl_vm.nic[0].ips
}

output "datacenterId" {
  value = ionoscloud_datacenter.simpl_vm.id
}

output "volumeId" {
  value = ionoscloud_server.simpl_vm.boot_volume
}
