Skip to content

Commit

Permalink
feat: expore the server group configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeo committed Mar 25, 2024
1 parent 8ba1908 commit 7ac6f0d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/tofuutils/pre-commit-opentofu
rev: 65ac74a0fd483b19b93293918c088067a9979e6d
rev: v1.0.2
hooks:
- id: tofu_fmt
- id: tofu_checkov
Expand Down
14 changes: 12 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ locals {
operator_replica = length(var.servers) > 1 ? 2 : 1
}

resource "openstack_compute_servergroup_v2" "servers" {
name = "${var.name}-servers"
policies = ["anti-affinity"]
}

resource "openstack_compute_servergroup_v2" "agents" {
name = "${var.name}-servers"
policies = ["soft-anti-affinity"]
}

module "servers" {
source = "./node"

Expand All @@ -33,7 +43,7 @@ module "servers" {
boot_volume_type = each.value.boot_volume_type

availability_zones = coalesce(each.value.availability_zones, [])
affinity = coalesce(each.value.affinity, "soft-anti-affinity")
group_id = each.value.group_id != null ? each.value.group_id : openstack_compute_servergroup_v2.servers.id

rke2_version = each.value.rke2_version
rke2_config = each.value.rke2_config
Expand Down Expand Up @@ -144,7 +154,7 @@ module "agents" {
boot_volume_type = each.value.boot_volume_type

availability_zones = coalesce(each.value.availability_zones, [])
affinity = coalesce(each.value.affinity, "soft-anti-affinity")
group_id = each.value.group_id != null ? each.value.group_id : openstack_compute_servergroup_v2.agents.id

rke2_version = each.value.rke2_version
rke2_config = each.value.rke2_config
Expand Down
7 changes: 1 addition & 6 deletions node/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ data "openstack_images_image_v2" "image" {
most_recent = true
}

resource "openstack_compute_servergroup_v2" "servergroup" {
name = "${var.name}-servergroup"
policies = [var.affinity]
}

resource "openstack_blockstorage_volume_v3" "volume" {
count = var.is_persisted ? var.nodes_count : 0
name = "${var.name}-${count.index + 1}-rke2"
Expand Down Expand Up @@ -53,7 +48,7 @@ resource "openstack_compute_instance_v2" "instance" {
}

scheduler_hints {
group = openstack_compute_servergroup_v2.servergroup.id
group = var.group_id
}

metadata = {
Expand Down
2 changes: 1 addition & 1 deletion node/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ variable "availability_zones" {
type = list(string)
}

variable "affinity" {
variable "group_id" {
type = string
}

Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ variable "bootstrap" {
variable "servers" {
type = list(object({
name = string
affinity = optional(string)
group_id = optional(string)
availability_zones = optional(list(string))
flavor_name = string
image_name = string
Expand Down Expand Up @@ -141,7 +141,7 @@ variable "agents" {
type = list(object({
name = string
nodes_count = number
affinity = optional(string)
group_id = optional(string)
availability_zones = optional(list(string))
flavor_name = string
image_name = string
Expand Down

0 comments on commit 7ac6f0d

Please sign in to comment.