-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
67 lines (55 loc) · 2.27 KB
/
main.tf
File metadata and controls
67 lines (55 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
locals {
# Use the user part of the username if var.prefix is not set or empty.
prefix = length(var.prefix) > 0 ? var.prefix : split("@", data.openstack_identity_auth_scope_v3.current.user_name)[0]
}
# Get a public ip-address, IPv6 soon available!
resource "openstack_networking_floatingip_v2" "external" {
count = var.vm_total
pool = "external"
}
# Each vm has an additional disk
resource "openstack_blockstorage_volume_v3" "storage" {
count = var.vm_total
name = "${local.prefix}-storage-${count.index}"
size = var.vm_additional_storage
}
resource "openstack_compute_instance_v2" "llm" {
# The amount of instances you want to create
count = var.vm_total
name = "${local.prefix}_llm_${count.index}"
flavor_name = var.vm_flavor_name
image_id = data.openstack_images_image_v2.ubuntu.id
key_pair = openstack_compute_keypair_v2.ssh-key.name
# Security groups (firewall)
security_groups = [
openstack_compute_secgroup_v2.llm.name,
openstack_compute_secgroup_v2.https.name,
]
# Here is where all the magic happens - vLLM setup with API key auth
user_data = templatefile("templates/user_data.yaml.tpl", {
additional_disk_name = "vdb"
vllm_model = var.vllm_model
vllm_api_key = local.vllm_api_key
vllm_max_model_len = var.vllm_max_model_len
vllm_gpu_memory_utilization = var.vllm_gpu_memory_utilization
huggingface_token = var.huggingface_token
})
network {
name = openstack_networking_network_v2.private.name
# Here we get the value of the count and add 10,
# so that each instance gets it's own unique IP
fixed_ip_v4 = cidrhost(var.subnet_cidr, count.index + 10)
}
depends_on = [openstack_networking_router_v2.router, openstack_networking_network_v2.private]
}
resource "openstack_compute_floatingip_associate_v2" "fip" {
count = var.vm_total
floating_ip = openstack_networking_floatingip_v2.external[count.index].address
instance_id = openstack_compute_instance_v2.llm[count.index].id
}
resource "openstack_compute_volume_attach_v2" "llm" {
count = var.vm_total
instance_id = openstack_compute_instance_v2.llm[count.index].id
volume_id = openstack_blockstorage_volume_v3.storage[count.index].id
}
# Outputs moved to outputs.tf