locals {
  image = "projects/debian-cloud/global/images/family/debian-11"
}

# ------------------------
# FRONTEND instance
# ------------------------

resource "google_compute_instance" "frontend" {
  name         = "frontend"
  machine_type = var.instance_type
  zone         = var.zone

  tags = ["frontend", "ssh"]

  boot_disk {
    initialize_params {
      size  = 10
      image = local.image
    }
  }

  network_interface {
    subnetwork   = var.frontend_subnet_id
    access_config {}
  }

  metadata = {
    enable-oslogin = "TRUE"
  }
}

# ------------------------
# BACKEND instance
# ------------------------

resource "google_compute_instance" "backend" {
  name         = "backend"
  machine_type = var.instance_type
  zone         = var.zone

  tags = ["backend", "ssh"]

  boot_disk {
    initialize_params {
      size  = 10
      image = local.image
    }
  }

  network_interface {
    subnetwork = var.backend_subnet_id
  }

  metadata = {
    enable-oslogin = "TRUE"
  }
}

# ------------------------
# DATABASE instance
# ------------------------

resource "google_compute_instance" "database" {
  name         = "database"
  machine_type = var.instance_type
  zone         = var.zone

  tags = ["database", "ssh"]

  boot_disk {
    initialize_params {
      size  = 20
      image = local.image
    }
  }

  network_interface {
    subnetwork = var.database_subnet_id
  }

  metadata = {
    enable-oslogin = "TRUE"
  }
}