Skip to content

Commit 7ac6f0d

Browse files
committed
feat: expore the server group configuration
1 parent 8ba1908 commit 7ac6f0d

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/tofuutils/pre-commit-opentofu
3-
rev: 65ac74a0fd483b19b93293918c088067a9979e6d
3+
rev: v1.0.2
44
hooks:
55
- id: tofu_fmt
66
- id: tofu_checkov

main.tf

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ locals {
1111
operator_replica = length(var.servers) > 1 ? 2 : 1
1212
}
1313

14+
resource "openstack_compute_servergroup_v2" "servers" {
15+
name = "${var.name}-servers"
16+
policies = ["anti-affinity"]
17+
}
18+
19+
resource "openstack_compute_servergroup_v2" "agents" {
20+
name = "${var.name}-servers"
21+
policies = ["soft-anti-affinity"]
22+
}
23+
1424
module "servers" {
1525
source = "./node"
1626

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

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

3848
rke2_version = each.value.rke2_version
3949
rke2_config = each.value.rke2_config
@@ -144,7 +154,7 @@ module "agents" {
144154
boot_volume_type = each.value.boot_volume_type
145155

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

149159
rke2_version = each.value.rke2_version
150160
rke2_config = each.value.rke2_config

node/main.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ data "openstack_images_image_v2" "image" {
33
most_recent = true
44
}
55

6-
resource "openstack_compute_servergroup_v2" "servergroup" {
7-
name = "${var.name}-servergroup"
8-
policies = [var.affinity]
9-
}
10-
116
resource "openstack_blockstorage_volume_v3" "volume" {
127
count = var.is_persisted ? var.nodes_count : 0
138
name = "${var.name}-${count.index + 1}-rke2"
@@ -53,7 +48,7 @@ resource "openstack_compute_instance_v2" "instance" {
5348
}
5449

5550
scheduler_hints {
56-
group = openstack_compute_servergroup_v2.servergroup.id
51+
group = var.group_id
5752
}
5853

5954
metadata = {

node/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ variable "availability_zones" {
4747
type = list(string)
4848
}
4949

50-
variable "affinity" {
50+
variable "group_id" {
5151
type = string
5252
}
5353

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ variable "bootstrap" {
109109
variable "servers" {
110110
type = list(object({
111111
name = string
112-
affinity = optional(string)
112+
group_id = optional(string)
113113
availability_zones = optional(list(string))
114114
flavor_name = string
115115
image_name = string
@@ -141,7 +141,7 @@ variable "agents" {
141141
type = list(object({
142142
name = string
143143
nodes_count = number
144-
affinity = optional(string)
144+
group_id = optional(string)
145145
availability_zones = optional(list(string))
146146
flavor_name = string
147147
image_name = string

0 commit comments

Comments
 (0)