upcloud: v5.6.0 and better server groups (#11311)

pull/11258/head
Robin Wallace 2024-06-26 10:42:21 +02:00 committed by GitHub
parent c352773737
commit 15b62cc7ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 16 deletions

View File

@ -54,11 +54,12 @@ resource "upcloud_server" "master" {
if machine.node_type == "master" if machine.node_type == "master"
} }
hostname = "${local.resource-prefix}${each.key}" hostname = "${local.resource-prefix}${each.key}"
plan = each.value.plan plan = each.value.plan
cpu = each.value.plan == null ? each.value.cpu : null cpu = each.value.plan == null ? null : each.value.cpu
mem = each.value.plan == null ? each.value.mem : null mem = each.value.plan == null ? null : each.value.mem
zone = var.zone zone = var.zone
server_group = each.value.server_group == null ? null : upcloud_server_group.server_groups[each.value.server_group].id
template { template {
storage = var.template_name storage = var.template_name
@ -111,11 +112,13 @@ resource "upcloud_server" "worker" {
if machine.node_type == "worker" if machine.node_type == "worker"
} }
hostname = "${local.resource-prefix}${each.key}" hostname = "${local.resource-prefix}${each.key}"
plan = each.value.plan plan = each.value.plan
cpu = each.value.plan == null ? each.value.cpu : null cpu = each.value.plan == null ? null : each.value.cpu
mem = each.value.plan == null ? each.value.mem : null mem = each.value.plan == null ? null : each.value.mem
zone = var.zone zone = var.zone
server_group = each.value.server_group == null ? null : upcloud_server_group.server_groups[each.value.server_group].id
template { template {
storage = var.template_name storage = var.template_name
@ -513,7 +516,17 @@ resource "upcloud_loadbalancer" "lb" {
name = "${local.resource-prefix}lb" name = "${local.resource-prefix}lb"
plan = var.loadbalancer_plan plan = var.loadbalancer_plan
zone = var.zone zone = var.zone
network = upcloud_network.private.id networks {
name = "Private-Net"
type = "private"
family = "IPv4"
network = upcloud_network.private.id
}
networks {
name = "Public-Net"
type = "public"
family = "IPv4"
}
} }
resource "upcloud_loadbalancer_backend" "lb_backend" { resource "upcloud_loadbalancer_backend" "lb_backend" {
@ -534,6 +547,9 @@ resource "upcloud_loadbalancer_frontend" "lb_frontend" {
mode = "tcp" mode = "tcp"
port = each.value.port port = each.value.port
default_backend_name = upcloud_loadbalancer_backend.lb_backend[each.key].name default_backend_name = upcloud_loadbalancer_backend.lb_backend[each.key].name
networks {
name = "Public-Net"
}
} }
resource "upcloud_loadbalancer_static_backend_member" "lb_backend_member" { resource "upcloud_loadbalancer_static_backend_member" "lb_backend_member" {
@ -557,5 +573,9 @@ resource "upcloud_server_group" "server_groups" {
title = each.key title = each.key
anti_affinity_policy = each.value.anti_affinity_policy anti_affinity_policy = each.value.anti_affinity_policy
labels = {} labels = {}
members = [for server in each.value.servers : merge(upcloud_server.master, upcloud_server.worker)[server].id] # Managed upstream via upcloud_server resource
members = []
lifecycle {
ignore_changes = [members]
}
} }

View File

@ -20,6 +20,7 @@ variable "machines" {
cpu = string cpu = string
mem = string mem = string
disk_size = number disk_size = number
server_group : string
additional_disks = map(object({ additional_disks = map(object({
size = number size = number
tier = string tier = string
@ -104,6 +105,5 @@ variable "server_groups" {
type = map(object({ type = map(object({
anti_affinity_policy = string anti_affinity_policy = string
servers = list(string)
})) }))
} }

View File

@ -3,7 +3,7 @@ terraform {
required_providers { required_providers {
upcloud = { upcloud = {
source = "UpCloudLtd/upcloud" source = "UpCloudLtd/upcloud"
version = "~>2.12.0" version = "~>5.6.0"
} }
} }
required_version = ">= 0.13" required_version = ">= 0.13"

View File

@ -32,6 +32,7 @@ variable "machines" {
cpu = string cpu = string
mem = string mem = string
disk_size = number disk_size = number
server_group : string
additional_disks = map(object({ additional_disks = map(object({
size = number size = number
tier = string tier = string
@ -142,7 +143,6 @@ variable "server_groups" {
type = map(object({ type = map(object({
anti_affinity_policy = string anti_affinity_policy = string
servers = list(string)
})) }))
default = {} default = {}

View File

@ -3,7 +3,7 @@ terraform {
required_providers { required_providers {
upcloud = { upcloud = {
source = "UpCloudLtd/upcloud" source = "UpCloudLtd/upcloud"
version = "~>2.12.0" version = "~>5.6.0"
} }
} }
required_version = ">= 0.13" required_version = ">= 0.13"