Skip to content

Commit

Permalink
Use custom node-template
Browse files Browse the repository at this point in the history
  • Loading branch information
sferatime committed Feb 11, 2025
1 parent a1e32fd commit 31c9a7b
Showing 1 changed file with 19 additions and 57 deletions.
76 changes: 19 additions & 57 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,12 @@ locals {
autoscaled_node_pools = merge([{ for node_pool in var.cluster_configurations.node_pools : "${var.cluster_name}--${node_pool.name}" => node_pool if node_pool.autoscaling }]...)
}

resource "rancher2_node_template" "hetzner" {
for_each = local.required_node_templates
name = each.key
driver_id = "hetzner"
hetzner_config {
api_token = var.hetzner_token
image = each.value.image
server_location = each.value.server_location
server_type = each.value.server_type
networks = var.management_network_id
use_private_network = each.value.use_private_network
userdata = file("${path.module}/cloud-init/init.yaml")
}
labels = merge({
"cluster-name" = var.cluster_name
}, each.value.labels)
}

# resource "rancher2_node_template" "hetzner-autoscaled" {
# for_each = local.autoscaled_node_templates
# name = each.key
# driver_id = "hetzner"
# hetzner_config {
# api_token = var.hetzner_token
# image = each.value.image
# server_location = each.value.server_location
# server_type = each.value.server_type
# networks = var.management_network_id
# use_private_network = each.value.use_private_network
# userdata = file("${path.module}/cloud-init/init.yaml")
# }
# labels = merge({
# "cluster-name" = var.cluster_name
# }, each.value.labels)
# }

resource "rancher2_node_pool" "hetzner" {
for_each = local.required_node_pools
cluster_id = rancher2_cluster.hetzner.id
name = each.key
hostname_prefix = each.key
node_template_id = rancher2_node_template.hetzner["${each.value.server_type}--${each.value.server_location}--${each.value.image}--${each.value.name}"].id
# node_template_id = "cattle-global-nt:nt-${random_string._autoscaled_template_name_hash["${each.value.server_type}--${each.value.server_location}--${each.value.image}--${each.value.name}"].result}"
node_template_id = "cattle-global-nt:nt-${random_string._template_name_hash["${each.value.server_type}--${each.value.server_location}--${each.value.image}--${each.value.name}"].result}"
quantity = each.value.quantity
control_plane = each.value.control_plane
etcd = each.value.etcd
Expand All @@ -61,15 +24,14 @@ resource "rancher2_node_pool" "hetzner" {
effect = node_taints.value.effect
}
}
# depends_on = [kubectl_manifest.node_template]
depends_on = [kubectl_manifest.node_template]
}

resource "rancher2_node_pool" "hetzner-autoscaled" {
for_each = local.autoscaled_node_pools
cluster_id = rancher2_cluster.hetzner.id
name = each.key
hostname_prefix = each.key
# node_template_id = rancher2_node_template.hetzner-autoscaled["${each.value.server_type}--${each.value.server_location}--${each.value.image}--${each.value.name}"].id
node_template_id = "cattle-global-nt:nt-${random_string._autoscaled_template_name_hash["${each.value.server_type}--${each.value.server_location}--${each.value.image}--${each.value.name}"].result}"
quantity = each.value.quantity
control_plane = each.value.control_plane
Expand Down Expand Up @@ -147,23 +109,23 @@ resource "random_string" "_autoscaled_template_name_hash" {
upper = false
}

# resource "kubectl_manifest" "node_template" {
# provider = kubectl.rancher_mgmt_cluster
# for_each = local.required_node_templates
# yaml_body = templatefile("${path.module}/templates/node-template.yaml.tftpl", {
# default_admin_id = data.rancher2_user.default_admin.id
# hcloud_token = var.hetzner_token
# name = each.key
# name_hash = random_string._template_name_hash[each.key].result
# firewall_id = hcloud_firewall.node_firewall_ssh.id
# cluster_name = var.cluster_name
# image = each.value.image
# server_location = each.value.server_location
# server_type = each.value.server_type
# use_private_network = each.value.use_private_network
# userdata = indent(4, file("${path.module}/cloud-init/init.yaml"))
# })
# }
resource "kubectl_manifest" "node_template" {
provider = kubectl.rancher_mgmt_cluster
for_each = local.required_node_templates
yaml_body = nonsensitive(templatefile("${path.module}/templates/node-template.yaml.tftpl", {
default_admin_id = data.rancher2_user.default_admin.id
hcloud_token = var.hetzner_token
name = each.key
name_hash = random_string._template_name_hash[each.key].result
firewall_id = hcloud_firewall.node_firewall_ssh.id
cluster_name = var.cluster_name
image = each.value.image
server_location = each.value.server_location
server_type = each.value.server_type
use_private_network = each.value.use_private_network
userdata = indent(4, file("${path.module}/cloud-init/init.yaml"))
}))
}

resource "kubectl_manifest" "autoscaled_node_template" {
provider = kubectl.rancher_mgmt_cluster
Expand Down

0 comments on commit 31c9a7b

Please sign in to comment.