mirror of
https://github.com/optim-enterprises-bv/terraform-talos.git
synced 2025-11-02 11:18:35 +00:00
Use module to run web/worker
This commit is contained in:
@@ -4,7 +4,7 @@ module "controlplane" {
|
|||||||
for_each = { for idx, name in local.regions : name => idx }
|
for_each = { for idx, name in local.regions : name => idx }
|
||||||
region = each.key
|
region = each.key
|
||||||
instance_count = lookup(try(var.controlplane[each.key], {}), "count", 0)
|
instance_count = lookup(try(var.controlplane[each.key], {}), "count", 0)
|
||||||
instance_flavor = "d2-2"
|
instance_flavor = lookup(try(var.controlplane[each.key], {}), "instance_type", "d2-2")
|
||||||
instance_image = data.openstack_images_image_v2.talos[each.key].id
|
instance_image = data.openstack_images_image_v2.talos[each.key].id
|
||||||
instance_params = merge(var.kubernetes, {
|
instance_params = merge(var.kubernetes, {
|
||||||
ipv4_local_network = local.network[each.key].cidr
|
ipv4_local_network = local.network[each.key].cidr
|
||||||
|
|||||||
@@ -1,62 +1,18 @@
|
|||||||
|
|
||||||
# resource "openstack_networking_port_v2" "web" {
|
module "web" {
|
||||||
# for_each = { for idx, name in local.regions : name => idx }
|
source = "./modules/worker"
|
||||||
# region = each.key
|
for_each = { for idx, name in local.regions : name => idx }
|
||||||
# name = "web-${lower(each.key)}-${each.value + 1}"
|
region = each.key
|
||||||
# network_id = local.network[each.key].id
|
instance_count = lookup(try(var.instances[each.key], {}), "web_count", 0)
|
||||||
# admin_state_up = true
|
instance_name = "web"
|
||||||
|
instance_flavor = lookup(try(var.instances[each.key], {}), "web_instance_type", 0)
|
||||||
|
instance_image = data.openstack_images_image_v2.talos[each.key].id
|
||||||
|
instance_params = merge(var.kubernetes, {
|
||||||
|
ipv4_local_network = local.network[each.key].cidr
|
||||||
|
ipv4_local_gw = local.network_public[each.key].gateway
|
||||||
|
lbv4 = module.controlplane[each.key].controlplane_lb
|
||||||
|
})
|
||||||
|
|
||||||
# fixed_ip {
|
network_internal = local.network_public[each.key]
|
||||||
# subnet_id = local.network_public[each.key].id
|
network_external = local.network_external[each.key]
|
||||||
# ip_address = cidrhost(local.network_public[each.key].cidr, 21 + each.value)
|
}
|
||||||
# }
|
|
||||||
# }
|
|
||||||
|
|
||||||
# locals {
|
|
||||||
# web_labels = "project.io/node-pool=web"
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # resource "openstack_compute_instance_v2" "web" {
|
|
||||||
# # for_each = { for idx, name in local.regions : name => idx }
|
|
||||||
# # region = each.key
|
|
||||||
|
|
||||||
# # name = "web-${lower(each.key)}-${each.value + 1}"
|
|
||||||
# # flavor_name = "d2-2"
|
|
||||||
# # image_id = data.openstack_images_image_v2.talos[each.key].id
|
|
||||||
# # key_pair = data.openstack_compute_keypair_v2.terraform[each.key].name
|
|
||||||
|
|
||||||
# # user_data = templatefile("${path.module}/templates/worker.yaml.tpl",
|
|
||||||
# # merge(var.kubernetes, {
|
|
||||||
# # name = "web-${lower(each.key)}-${each.value + 1}"
|
|
||||||
# # lbv4 = openstack_networking_port_v2.vip[each.key].fixed_ip[0].ip_address
|
|
||||||
# # nodeSubnets = local.network_public[each.key].cidr
|
|
||||||
# # labels = local.web_labels
|
|
||||||
# # })
|
|
||||||
# # )
|
|
||||||
|
|
||||||
# # network {
|
|
||||||
# # name = local.network_external[each.key].name
|
|
||||||
# # }
|
|
||||||
# # network {
|
|
||||||
# # port = openstack_networking_port_v2.web[each.key].id
|
|
||||||
# # }
|
|
||||||
|
|
||||||
# # lifecycle {
|
|
||||||
# # ignore_changes = [flavor_name, image_id, user_data]
|
|
||||||
# # }
|
|
||||||
# # }
|
|
||||||
|
|
||||||
# resource "local_file" "web" {
|
|
||||||
# for_each = { for idx, name in local.regions : name => idx }
|
|
||||||
|
|
||||||
# content = templatefile("${path.module}/templates/worker.yaml.tpl",
|
|
||||||
# merge(var.kubernetes, {
|
|
||||||
# name = "web-${lower(each.key)}-${each.value + 1}"
|
|
||||||
# lbv4 = openstack_networking_port_v2.vip[each.key].fixed_ip[0].ip_address
|
|
||||||
# nodeSubnets = local.network_public[each.key].cidr
|
|
||||||
# labels = local.web_labels
|
|
||||||
# })
|
|
||||||
# )
|
|
||||||
# filename = "_cfgs/web-${lower(each.key)}-${each.value + 1}.yaml"
|
|
||||||
# file_permission = "0600"
|
|
||||||
# }
|
|
||||||
|
|||||||
@@ -1,44 +1,17 @@
|
|||||||
|
|
||||||
# resource "openstack_networking_port_v2" "worker" {
|
module "worker" {
|
||||||
# for_each = { for idx, name in local.regions : name => idx }
|
source = "./modules/worker"
|
||||||
# region = each.key
|
for_each = { for idx, name in local.regions : name => idx }
|
||||||
# name = "worker-${lower(each.key)}-${each.value + 1}"
|
region = each.key
|
||||||
# network_id = local.network[each.key].id
|
instance_count = lookup(try(var.instances[each.key], {}), "worker_count", 0)
|
||||||
# admin_state_up = true
|
instance_name = "worker"
|
||||||
|
instance_flavor = lookup(try(var.instances[each.key], {}), "worker_instance_type", 0)
|
||||||
|
instance_image = data.openstack_images_image_v2.talos[each.key].id
|
||||||
|
instance_params = merge(var.kubernetes, {
|
||||||
|
ipv4_local_network = local.network[each.key].cidr
|
||||||
|
ipv4_local_gw = local.network_public[each.key].gateway
|
||||||
|
lbv4 = module.controlplane[each.key].controlplane_lb
|
||||||
|
})
|
||||||
|
|
||||||
# fixed_ip {
|
network_internal = local.network_public[each.key]
|
||||||
# subnet_id = local.network_private[each.key].id
|
}
|
||||||
# ip_address = cidrhost(local.network_private[each.key].cidr, 31 + each.value)
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
|
|
||||||
# locals {
|
|
||||||
# worker_labels = "project.io/node-pool=worker"
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # resource "openstack_compute_instance_v2" "worker" {
|
|
||||||
# # for_each = { for idx, name in local.regions : name => idx }
|
|
||||||
# # region = each.key
|
|
||||||
|
|
||||||
# # name = "worker-${lower(each.key)}-${each.value + 1}"
|
|
||||||
# # flavor_name = "d2-2"
|
|
||||||
# # image_id = data.openstack_images_image_v2.talos[each.key].id
|
|
||||||
# # key_pair = data.openstack_compute_keypair_v2.terraform[each.key].name
|
|
||||||
|
|
||||||
# # user_data = templatefile("${path.module}/templates/worker.yaml.tpl",
|
|
||||||
# # merge(var.kubernetes, {
|
|
||||||
# # name = "web-${lower(each.key)}-${each.value + 1}"
|
|
||||||
# # lbv4 = openstack_networking_port_v2.vip[each.key].fixed_ip[0].ip_address
|
|
||||||
# # nodeSubnets = local.network_private[each.key].cidr
|
|
||||||
# # labels = local.web_labels
|
|
||||||
# # })
|
|
||||||
# # )
|
|
||||||
|
|
||||||
# # network {
|
|
||||||
# # port = openstack_networking_port_v2.worker[each.key].id
|
|
||||||
# # }
|
|
||||||
|
|
||||||
# # lifecycle {
|
|
||||||
# # ignore_changes = [flavor_name, image_id, user_data]
|
|
||||||
# # }
|
|
||||||
# # }
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
|
||||||
|
output "controlplane_lb" {
|
||||||
|
description = "Kubernetes controlplane local loadbalancer ip"
|
||||||
|
value = local.ipv4_local_vip
|
||||||
|
}
|
||||||
|
|
||||||
output "controlplane_endpoints" {
|
output "controlplane_endpoints" {
|
||||||
description = "Kubernetes controlplane endpoint"
|
description = "Kubernetes controlplane endpoint"
|
||||||
value = [for ip in try(openstack_networking_port_v2.controlplane_public[*].all_fixed_ips, []) : ip]
|
value = [for ip in try(openstack_networking_port_v2.controlplane_public[*].all_fixed_ips, []) : ip]
|
||||||
|
|||||||
63
openstack/modules/worker/main.tf
Normal file
63
openstack/modules/worker/main.tf
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
resource "openstack_networking_port_v2" "worker" {
|
||||||
|
count = var.instance_count
|
||||||
|
region = var.region
|
||||||
|
name = "${var.instance_name}-${lower(var.region)}-${count.index + 1}"
|
||||||
|
network_id = var.network_internal.network_id
|
||||||
|
admin_state_up = true
|
||||||
|
|
||||||
|
fixed_ip {
|
||||||
|
subnet_id = var.network_internal.subnet_id
|
||||||
|
ip_address = cidrhost(var.network_internal.cidr, var.instance_ip_start + count.index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
worker_labels = "topology.kubernetes.io/region=nova,topology.kubernetes.io/zone=${var.region},project.io/node-pool=${var.instance_name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "openstack_compute_instance_v2" "worker" {
|
||||||
|
count = var.instance_count
|
||||||
|
region = var.region
|
||||||
|
name = "${var.instance_name}-${lower(var.region)}-${count.index + 1}"
|
||||||
|
flavor_name = var.instance_flavor
|
||||||
|
image_id = var.instance_image
|
||||||
|
|
||||||
|
user_data = templatefile("${path.module}/../../templates/worker.yaml.tpl",
|
||||||
|
merge(var.instance_params, {
|
||||||
|
name = "${var.instance_name}-${lower(var.region)}-${count.index + 1}"
|
||||||
|
labels = local.worker_labels
|
||||||
|
iface = try(var.network_external.name, "") == "" ? "eth0" : "eth1"
|
||||||
|
nodeSubnets = var.network_internal.cidr
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
dynamic "network" {
|
||||||
|
for_each = try([var.network_external.name], [])
|
||||||
|
content {
|
||||||
|
name = network.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
network {
|
||||||
|
port = openstack_networking_port_v2.worker[count.index].id
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycle {
|
||||||
|
ignore_changes = [flavor_name, image_id, user_data]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "local_file" "controlplane" {
|
||||||
|
count = var.instance_count
|
||||||
|
|
||||||
|
content = templatefile("${path.module}/../../templates/worker.yaml.tpl",
|
||||||
|
merge(var.instance_params, {
|
||||||
|
name = "${var.instance_name}-${lower(var.region)}-${count.index + 1}"
|
||||||
|
labels = local.worker_labels
|
||||||
|
iface = try(var.network_external.name, "") == "" ? "eth0" : "eth1"
|
||||||
|
nodeSubnets = var.network_internal.cidr
|
||||||
|
})
|
||||||
|
)
|
||||||
|
filename = "_cfgs/${var.instance_name}-${lower(var.region)}-${count.index + 1}.yaml"
|
||||||
|
file_permission = "0600"
|
||||||
|
}
|
||||||
5
openstack/modules/worker/outputs.tf
Normal file
5
openstack/modules/worker/outputs.tf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
output "worker_endpoints" {
|
||||||
|
description = "Kubernetes worker endpoint"
|
||||||
|
value = [for ip in try(openstack_networking_port_v2.worker[*].all_fixed_ips, []) : ip]
|
||||||
|
}
|
||||||
46
openstack/modules/worker/variables.tf
Normal file
46
openstack/modules/worker/variables.tf
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
variable "region" {
|
||||||
|
description = "Region"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "network_internal" {
|
||||||
|
description = "Internal network"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "network_external" {
|
||||||
|
description = "External network"
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_count" {
|
||||||
|
description = "Instances in region"
|
||||||
|
type = number
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_name" {
|
||||||
|
description = "Instance name prefix"
|
||||||
|
type = string
|
||||||
|
default = "worker"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_flavor" {
|
||||||
|
description = "Instance type"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_image" {
|
||||||
|
description = "Instance image"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_params" {
|
||||||
|
description = "Instance template parameters"
|
||||||
|
type = map(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_ip_start" {
|
||||||
|
description = "Instances in region"
|
||||||
|
type = number
|
||||||
|
default = 21
|
||||||
|
}
|
||||||
10
openstack/modules/worker/versions.tf
Normal file
10
openstack/modules/worker/versions.tf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
openstack = {
|
||||||
|
source = "terraform-provider-openstack/openstack"
|
||||||
|
version = "~> 1.47.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
required_version = ">= 1.0"
|
||||||
|
}
|
||||||
@@ -20,10 +20,19 @@ machine:
|
|||||||
network:
|
network:
|
||||||
hostname: "${name}"
|
hostname: "${name}"
|
||||||
interfaces:
|
interfaces:
|
||||||
|
- interface: ${iface}
|
||||||
|
dhcp: true
|
||||||
|
routes:
|
||||||
|
- network: ${ipv4_local_network}
|
||||||
|
gateway: ${ipv4_local_gw}
|
||||||
- interface: dummy0
|
- interface: dummy0
|
||||||
addresses:
|
addresses:
|
||||||
- 169.254.2.53/32
|
- 169.254.2.53/32
|
||||||
- fd00::169:254:2:53/128
|
- fd00::169:254:2:53/128
|
||||||
|
extraHostEntries:
|
||||||
|
- ip: ${lbv4}
|
||||||
|
aliases:
|
||||||
|
- ${apiDomain}
|
||||||
sysctls:
|
sysctls:
|
||||||
net.core.somaxconn: 65535
|
net.core.somaxconn: 65535
|
||||||
net.core.netdev_max_backlog: 4096
|
net.core.netdev_max_backlog: 4096
|
||||||
|
|||||||
Reference in New Issue
Block a user