2023-02-27 12:19:52 -05:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
openstack = {
|
|
|
|
source = "terraform-provider-openstack/openstack"
|
2024-02-12 09:25:23 -05:00
|
|
|
version = "1.54.1"
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2023-07-03 10:33:00 -04:00
|
|
|
tags = distinct(sort(concat(var.tags, ["constellation-role-${var.role}"], ["constellation-node-group-${var.node_group_name}"])))
|
|
|
|
group_uid = random_id.uid.hex
|
2023-07-24 04:30:53 -04:00
|
|
|
name = "${var.base_name}-${var.role}-${local.group_uid}"
|
2023-07-03 10:33:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "random_id" "uid" {
|
|
|
|
byte_length = 4
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
|
2024-02-14 10:37:26 -05:00
|
|
|
resource "openstack_networking_port_v2" "port" {
|
|
|
|
name = "${local.name}-${count.index}"
|
|
|
|
count = var.initial_count
|
|
|
|
admin_state_up = "true"
|
|
|
|
|
|
|
|
network_id = var.network_id
|
|
|
|
fixed_ip {
|
|
|
|
subnet_id = var.subnet_id
|
|
|
|
}
|
|
|
|
|
|
|
|
security_group_ids = var.security_groups
|
|
|
|
}
|
|
|
|
|
2023-06-01 06:33:06 -04:00
|
|
|
# TODO(malt3): get this API enabled in the test environment
|
2023-02-27 12:19:52 -05:00
|
|
|
# resource "openstack_compute_servergroup_v2" "instance_group" {
|
|
|
|
# name = local.name
|
|
|
|
# policies = ["soft-anti-affinity"]
|
|
|
|
# }
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "instance_group_member" {
|
2024-02-14 10:37:26 -05:00
|
|
|
name = "${local.name}-${count.index}"
|
|
|
|
count = var.initial_count
|
|
|
|
image_id = var.image_id
|
|
|
|
flavor_id = var.flavor_id
|
|
|
|
tags = local.tags
|
2023-06-01 06:33:06 -04:00
|
|
|
# TODO(malt3): get this API enabled in the test environment
|
2023-02-27 12:19:52 -05:00
|
|
|
# scheduler_hints {
|
|
|
|
# group = openstack_compute_servergroup_v2.instance_group.id
|
|
|
|
# }
|
|
|
|
network {
|
2024-02-14 10:37:26 -05:00
|
|
|
port = openstack_networking_port_v2.port[count.index].id
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
block_device {
|
|
|
|
uuid = var.image_id
|
|
|
|
source_type = "image"
|
|
|
|
destination_type = "local"
|
|
|
|
boot_index = 0
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
block_device {
|
|
|
|
source_type = "blank"
|
|
|
|
destination_type = "volume"
|
|
|
|
volume_size = var.disk_size
|
2023-04-27 03:08:43 -04:00
|
|
|
volume_type = var.state_disk_type
|
2023-02-27 12:19:52 -05:00
|
|
|
boot_index = 1
|
|
|
|
delete_on_termination = true
|
|
|
|
}
|
|
|
|
metadata = {
|
2023-06-23 06:08:30 -04:00
|
|
|
constellation-role = var.role
|
2023-03-01 02:48:17 -05:00
|
|
|
constellation-uid = var.uid
|
2023-02-27 12:19:52 -05:00
|
|
|
constellation-init-secret-hash = var.init_secret_hash
|
2023-03-03 04:10:36 -05:00
|
|
|
openstack-auth-url = var.identity_internal_url
|
2023-03-03 09:28:28 -05:00
|
|
|
openstack-username = var.openstack_username
|
|
|
|
openstack-password = var.openstack_password
|
|
|
|
openstack-user-domain-name = var.openstack_user_domain_name
|
2023-02-27 12:19:52 -05:00
|
|
|
}
|
|
|
|
availability_zone_hints = var.availability_zone
|
|
|
|
}
|