99 lines
2 KiB
Terraform
99 lines
2 KiB
Terraform
|
|
|
||
|
|
|
||
|
|
// Compute
|
||
|
|
// ----------------------------------
|
||
|
|
|
||
|
|
// The instance for K3S
|
||
|
|
resource "google_compute_instance" "k3s" {
|
||
|
|
name = "k3s-vm-1"
|
||
|
|
machine_type = "e2-small" # This instance will have 2 Gb of RAM
|
||
|
|
zone = var.zone
|
||
|
|
|
||
|
|
tags = ["web"]
|
||
|
|
|
||
|
|
// Set the boot disk and the image (10 Gb)
|
||
|
|
boot_disk {
|
||
|
|
initialize_params {
|
||
|
|
image = "debian-cloud/debian-12"
|
||
|
|
size = 10
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Configuration to be a Spot Instance, to reduce costs
|
||
|
|
scheduling {
|
||
|
|
automatic_restart = true
|
||
|
|
}
|
||
|
|
# scheduling {
|
||
|
|
# preemptible = false
|
||
|
|
# automatic_restart = true
|
||
|
|
# provisioning_model = "SPOT"
|
||
|
|
# instance_termination_action = "STOP"
|
||
|
|
# }
|
||
|
|
|
||
|
|
// attach a disk for K3S
|
||
|
|
attached_disk {
|
||
|
|
source = google_compute_disk.k3s_disk.id
|
||
|
|
device_name = "k3s-disk"
|
||
|
|
}
|
||
|
|
|
||
|
|
// attach a disk for app data
|
||
|
|
attached_disk {
|
||
|
|
source = google_compute_disk.app_data_disk.id
|
||
|
|
device_name = "app-data-disk"
|
||
|
|
}
|
||
|
|
|
||
|
|
network_interface {
|
||
|
|
network = "default"
|
||
|
|
|
||
|
|
// enable ephemeral ip
|
||
|
|
access_config {}
|
||
|
|
}
|
||
|
|
|
||
|
|
labels = {
|
||
|
|
env = var.env
|
||
|
|
region = var.region
|
||
|
|
app = var.app_name
|
||
|
|
sensitive = "false"
|
||
|
|
}
|
||
|
|
|
||
|
|
metadata_startup_script = file("scripts/k3s-vm-startup.sh")
|
||
|
|
allow_stopping_for_update = true
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// Storage
|
||
|
|
// ----------------------------------
|
||
|
|
|
||
|
|
// The disk attached to the instance (15 Gb)
|
||
|
|
resource "google_compute_disk" "k3s_disk" {
|
||
|
|
name = "k3s-disk"
|
||
|
|
size = 15
|
||
|
|
type = "pd-standard"
|
||
|
|
zone = var.zone
|
||
|
|
}
|
||
|
|
|
||
|
|
// The disk for app data (20 Gb)
|
||
|
|
resource "google_compute_disk" "app_data_disk" {
|
||
|
|
name = "app-data-disk"
|
||
|
|
size = 20
|
||
|
|
type = "pd-standard"
|
||
|
|
zone = var.zone
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
data "google_project" "project" {
|
||
|
|
project_id = var.project_name # Use variable from tfvars
|
||
|
|
}
|
||
|
|
|
||
|
|
output "project_number" {
|
||
|
|
value = data.google_project.project.number
|
||
|
|
}
|
||
|
|
|
||
|
|
output "k3s_vm_public_ip" {
|
||
|
|
value = google_compute_instance.k3s.network_interface[0].access_config[0].nat_ip
|
||
|
|
description = "Ephemeral public IP of the k3s VM"
|
||
|
|
}
|