matrixtest-IaC/kube.tf

63 lines
2.6 KiB
HCL

resource "openstack_networking_port_v2" "kubeport" {
name = "kube${count.index + 1}-matrix-test-sunet-se-port"
# We create as many ports as there are instances created
count = var.kubesize # size of cluster
network_id = data.openstack_networking_network_v2.public.id
# A list of security group ID
security_group_ids = [
data.openstack_networking_secgroup_v2.sshfromjumphosts.id,
data.openstack_networking_secgroup_v2.allegress.id,
resource.openstack_networking_secgroup_v2.kubenode.id
]
admin_state_up = "true"
}
resource "openstack_blockstorage_volume_v3" "kubevolumeboot" {
count = var.kubesize # size of cluster
name = "kube${count.index + 1}-matrix-test-sunet-se-vol"
description = "OS volume for kubernetes node ${count.index + 1}"
size = 30
image_id = data.openstack_images_image_v2.debian12image.id
enable_online_resize = true # Allow us to resize volume while attached.
}
resource "openstack_blockstorage_volume_v3" "kubevolumesnap" {
count = var.kubesize # size of cluster
name = "kube${count.index + 1}-matrix-test-sunet-se-vol"
description = "OS volume for kubernetes node ${count.index + 1}"
size = 50
enable_online_resize = true # Allow us to resize volume while attached.
}
# Create instances of kubernetes nodes
resource "openstack_compute_instance_v2" "kube" {
name = "kube${count.index + 1}.matrix.test.sunet.se"
count = var.kubesize
flavor_id = data.openstack_compute_flavor_v2.b2c4r16.id
key_pair = data.openstack_compute_keypair_v2.manderssonpub.id
security_groups = [
data.openstack_networking_secgroup_v2.sshfromjumphosts.name,
data.openstack_networking_secgroup_v2.allegress.name,
resource.openstack_networking_secgroup_v2.kubenode.name
]
user_data = templatefile("kube-user.tpl",{})
network {
port = resource.openstack_networking_port_v2.kubeport[count.index].id
}
block_device {
uuid = resource.openstack_blockstorage_volume_v3.kubevolumeboot[count.index].id
source_type = "volume"
destination_type = "volume"
boot_index = 0
}
}
resource "openstack_compute_volume_attach_v2" "snapvolattach" {
instance_id = openstack_compute_instance_v2.kube[count.index].id
volume_id = openstack_blockstorage_volume_v3.kubevolumesnap[count.index].id
count = var.kubesize
}