138 lines
4.8 KiB
HCL
138 lines
4.8 KiB
HCL
# Kubernetes course VMs for InfraScience
|
|
# 14 Ubuntu 24.04 VMs with m1.large flavor, 100GB root volume, 200GB data volume,
|
|
# floating IP and DNS record each.
|
|
|
|
data "terraform_remote_state" "privnet_dns_router" {
|
|
backend = "local"
|
|
config = {
|
|
path = "../main_net_dns_router/terraform.tfstate"
|
|
}
|
|
}
|
|
|
|
module "labs_common_variables" {
|
|
source = "../../modules/labs_common_variables"
|
|
}
|
|
|
|
module "ssh_settings" {
|
|
source = "../../modules/ssh-key-ref"
|
|
}
|
|
|
|
locals {
|
|
vm_count = 14
|
|
dns_zone = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone
|
|
dns_zone_id = data.terraform_remote_state.privnet_dns_router.outputs.dns_zone_id
|
|
main_private_network_id = data.terraform_remote_state.privnet_dns_router.outputs.main_private_network_id
|
|
main_private_subnet_id = data.terraform_remote_state.privnet_dns_router.outputs.main_subnet_network_id
|
|
floating_ip_pool = data.terraform_remote_state.privnet_dns_router.outputs.floating_ip_pools.main_public_ip_pool
|
|
availability_zone = module.labs_common_variables.availability_zones_names.availability_zone_no_gpu
|
|
default_sg_name = module.labs_common_variables.default_security_group_name
|
|
}
|
|
|
|
# Look up the default security group by name, scoped to the infrascience project
|
|
data "openstack_networking_secgroup_v2" "default" {
|
|
name = local.default_sg_name
|
|
tenant_id = "3511cd5293dc435ea421aeb0edcfab43"
|
|
}
|
|
|
|
# --- Security group: SSH from anywhere ---
|
|
resource "openstack_networking_secgroup_v2" "ssh_from_anywhere" {
|
|
name = "corso-k8s-ssh-from-anywhere"
|
|
description = "Allow SSH access from anywhere"
|
|
delete_default_rules = true
|
|
}
|
|
|
|
resource "openstack_networking_secgroup_rule_v2" "ssh_from_anywhere_ingress" {
|
|
security_group_id = openstack_networking_secgroup_v2.ssh_from_anywhere.id
|
|
direction = "ingress"
|
|
ethertype = "IPv4"
|
|
protocol = "tcp"
|
|
port_range_min = 22
|
|
port_range_max = 22
|
|
remote_ip_prefix = "0.0.0.0/0"
|
|
}
|
|
|
|
# --- Network ports ---
|
|
resource "openstack_networking_port_v2" "corso_k8s_port" {
|
|
count = local.vm_count
|
|
name = format("corso-k8s-%02d-port", count.index + 1)
|
|
admin_state_up = true
|
|
network_id = local.main_private_network_id
|
|
security_group_ids = [
|
|
data.openstack_networking_secgroup_v2.default.id,
|
|
openstack_networking_secgroup_v2.ssh_from_anywhere.id,
|
|
]
|
|
fixed_ip {
|
|
subnet_id = local.main_private_subnet_id
|
|
}
|
|
}
|
|
|
|
# --- Data volumes (200 GB each) ---
|
|
resource "openstack_blockstorage_volume_v3" "corso_k8s_data_vol" {
|
|
count = local.vm_count
|
|
name = format("corso-k8s-%02d-data", count.index + 1)
|
|
size = 200
|
|
enable_online_resize = true
|
|
}
|
|
|
|
# --- Compute instances ---
|
|
resource "openstack_compute_instance_v2" "corso_k8s" {
|
|
count = local.vm_count
|
|
name = format("corso-k8s-%02d", count.index + 1)
|
|
availability_zone_hints = local.availability_zone
|
|
flavor_name = "m1.large"
|
|
key_pair = module.ssh_settings.ssh_key_name
|
|
|
|
block_device {
|
|
uuid = module.labs_common_variables.ubuntu_2404.uuid
|
|
source_type = "image"
|
|
volume_size = 100
|
|
boot_index = 0
|
|
destination_type = "volume"
|
|
delete_on_termination = false
|
|
}
|
|
|
|
network {
|
|
port = openstack_networking_port_v2.corso_k8s_port[count.index].id
|
|
}
|
|
|
|
user_data = file("${module.labs_common_variables.ubuntu2404_data_file}")
|
|
|
|
lifecycle {
|
|
ignore_changes = [
|
|
key_pair, user_data, network
|
|
]
|
|
}
|
|
}
|
|
|
|
# --- Attach data volumes ---
|
|
resource "openstack_compute_volume_attach_v2" "corso_k8s_data_vol_attach" {
|
|
count = local.vm_count
|
|
instance_id = openstack_compute_instance_v2.corso_k8s[count.index].id
|
|
volume_id = openstack_blockstorage_volume_v3.corso_k8s_data_vol[count.index].id
|
|
device = "/dev/vdb"
|
|
}
|
|
|
|
# --- Floating IPs ---
|
|
resource "openstack_networking_floatingip_v2" "corso_k8s_ip" {
|
|
count = local.vm_count
|
|
pool = local.floating_ip_pool
|
|
description = format("Public IP for corso-k8s-%02d", count.index + 1)
|
|
}
|
|
|
|
resource "openstack_networking_floatingip_associate_v2" "corso_k8s_ip" {
|
|
count = local.vm_count
|
|
floating_ip = openstack_networking_floatingip_v2.corso_k8s_ip[count.index].address
|
|
port_id = openstack_networking_port_v2.corso_k8s_port[count.index].id
|
|
}
|
|
|
|
# --- DNS records ---
|
|
resource "openstack_dns_recordset_v2" "corso_k8s_dns" {
|
|
count = local.vm_count
|
|
zone_id = local.dns_zone_id
|
|
name = format("corso-k8s-%02d.%s", count.index + 1, local.dns_zone.name)
|
|
description = format("Public IP of corso-k8s-%02d", count.index + 1)
|
|
ttl = 8600
|
|
type = "A"
|
|
records = [openstack_networking_floatingip_v2.corso_k8s_ip[count.index].address]
|
|
}
|