terraform: allow STACKIT / OpenStack instance type to be UUID or name

This commit is contained in:
Malte Poll 2024-02-28 13:29:28 +01:00
parent 79aaa77b6b
commit 3ce10eb00f
2 changed files with 11 additions and 5 deletions

View File

@ -913,7 +913,7 @@ func (c *Config) WithOpenStackProviderDefaults(openStackProvider string) *Config
c.Provider.OpenStack.YawolFlavorID = "3b11b27e-6c73-470d-b595-1d85b95a8cdf"
c.Provider.OpenStack.DeployCSIDriver = toPtr(true)
for groupName, group := range c.NodeGroups {
group.InstanceType = "2715eabe-3ffc-4c36-b02a-efa8c141a96a"
group.InstanceType = "m1a.4cd"
group.StateDiskType = "storage_premium_perf6"
c.NodeGroups[groupName] = group
}

View File

@ -11,6 +11,7 @@ locals {
tags = distinct(sort(concat(var.tags, ["constellation-role-${var.role}"], ["constellation-node-group-${var.node_group_name}"])))
group_uid = random_id.uid.hex
name = "${var.base_name}-${var.role}-${local.group_uid}"
flavor_id_is_uuid = length(var.flavor_id) == 36 && length(regexall("^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$", var.flavor_id)) == 1
}
resource "random_id" "uid" {
@ -36,11 +37,16 @@ resource "openstack_networking_port_v2" "port" {
# policies = ["soft-anti-affinity"]
# }
data "openstack_compute_flavor_v2" "flavor" {
flavor_id = local.flavor_id_is_uuid ? var.flavor_id : null
name = local.flavor_id_is_uuid ? null : var.flavor_id
}
resource "openstack_compute_instance_v2" "instance_group_member" {
name = "${local.name}-${count.index}"
count = var.initial_count
image_id = var.image_id
flavor_id = var.flavor_id
flavor_id = data.openstack_compute_flavor_v2.flavor.id
tags = local.tags
# TODO(malt3): get this API enabled in the test environment
# scheduler_hints {