not hardcode the ip allocation for agents

This commit is contained in:
jodhi 2022-02-24 22:49:36 +07:00
parent 7d301f2c6d
commit 58c630ba78
5 changed files with 10 additions and 8 deletions

View File

@ -12,7 +12,6 @@ module "agents" {
placement_group_id = hcloud_placement_group.k3s.id
location = var.location
network_id = hcloud_network.k3s.id
ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 513 + each.value.index)
server_type = each.value.server_type
labels = {
@ -45,7 +44,7 @@ resource "null_resource" "agents" {
token = random_password.k3s_token.result
kubelet-arg = "cloud-provider=external"
flannel-iface = "eth1"
node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 513 + each.value.index)
node-ip = module.agents[each.key].ipv4_address
node-label = var.automatically_upgrade_k3s ? ["k3s_upgrade=true"] : []
})
destination = "/tmp/config.yaml"

View File

@ -33,7 +33,7 @@ locals {
agent_nodepools = merge([
for nodepool_name, nodepool_obj in var.agent_nodepools : {
for index in range(nodepool_obj.count) :
for index in range(lookup(nodepool_obj, "count", var.agents_num)) :
format("%s-%s", nodepool_name, index) => {
index : index, # just for the compatibility with previous structure
server_type : nodepool_obj.server_type

View File

@ -14,7 +14,7 @@ resource "hcloud_server" "server" {
network {
network_id = var.network_id
ip = var.ip
ip = try(var.ip, null)
}
connection {

View File

@ -60,6 +60,7 @@ variable "network_id" {
}
variable "ip" {
default = null
description = "The IP"
type = string
nullable = true

View File

@ -52,12 +52,14 @@ variable "servers_num" {
type = number
}
variable "agents_num" {
description = "Default agent server type"
type = number
}
variable "agent_nodepools" {
description = "Number of agent nodes."
type = map(object({
server_type = string
count = number
}))
type = map(any)
}
variable "hetzner_ccm_version" {