From d00c930a45f8844c32ed8e9a1472e26f10da7eba Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 10 Apr 2023 11:42:25 +0200 Subject: [PATCH 1/2] added actual multilocation deployment of the cluster nodes --- .github/dependabot.yml | 14 ++++++++++++++ examples/simple-setup/main.tf | 5 +++++ main.tf | 28 ++++++++++++++-------------- variables.tf | 12 ++++++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) create mode 100755 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100755 index 0000000..07717a3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "terraform" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + labels: + - dependencies + - terraform \ No newline at end of file diff --git a/examples/simple-setup/main.tf b/examples/simple-setup/main.tf index 96b5a80..cac8301 100755 --- a/examples/simple-setup/main.tf +++ b/examples/simple-setup/main.tf @@ -5,3 +5,8 @@ module "rancher" { worker_node_count = 1 } +resource "local_file" "name" { + content = module.rancher.kube_config + filename = "kubeconfig.yaml" +} + diff --git a/main.tf b/main.tf index fe73554..cd69850 100755 --- a/main.tf +++ b/main.tf @@ -23,7 +23,7 @@ resource "hcloud_network" "main" { resource "hcloud_network_subnet" "main" { network_id = hcloud_network.main.id type = "cloud" - network_zone = "eu-central" + network_zone = var.network_zone ip_range = "10.0.0.0/16" } @@ -46,11 +46,11 @@ resource "random_password" "rke2_token" { locals { cluster_loadbalancer_running = length(data.hcloud_load_balancers.rke2_management.load_balancers) > 0 - cluster_ca = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).clusters[0].cluster.certificate-authority-data) - client_key = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).users[0].user.client-key-data) - client_cert = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).users[0].user.client-certificate-data) - cluster_host = "https://${hcloud_load_balancer.management_lb.ipv4}:6443" - kube_config = replace(data.remote_file.kubeconfig.content, "https://127.0.0.1:6443", local.cluster_host) + cluster_ca = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).clusters[0].cluster.certificate-authority-data) + client_key = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).users[0].user.client-key-data) + client_cert = data.remote_file.kubeconfig.content == "" ? "" : base64decode(yamldecode(data.remote_file.kubeconfig.content).users[0].user.client-certificate-data) + cluster_host = "https://${hcloud_load_balancer.management_lb.ipv4}:6443" + kube_config = replace(data.remote_file.kubeconfig.content, "https://127.0.0.1:6443", local.cluster_host) } resource "hcloud_server" "master" { @@ -58,12 +58,12 @@ resource "hcloud_server" "master" { name = "rke2-master-${random_string.master_node_suffix[count.index].result}" server_type = "cpx21" image = "ubuntu-20.04" - location = "hel1" + location = element(var.node_locations, count.index) ssh_keys = [hcloud_ssh_key.main.id] user_data = templatefile("${path.module}/scripts/rke-master.sh.tpl", { - RKE_TOKEN = random_password.rke2_token.result - INITIAL_MASTER = count.index == 0 && !local.cluster_loadbalancer_running - SERVER_ADDRESS = hcloud_load_balancer.management_lb.ipv4 + RKE_TOKEN = random_password.rke2_token.result + INITIAL_MASTER = count.index == 0 && !local.cluster_loadbalancer_running + SERVER_ADDRESS = hcloud_load_balancer.management_lb.ipv4 INSTALL_RKE2_VERSION = var.rke2_version }) @@ -100,11 +100,11 @@ resource "hcloud_server" "worker" { name = "rke2-worker-${random_string.worker_node_suffix[count.index].result}" server_type = "cpx21" image = "ubuntu-20.04" - location = "hel1" + location = element(var.node_locations, count.index) ssh_keys = [hcloud_ssh_key.main.id] user_data = templatefile("${path.module}/scripts/rke-worker.sh.tpl", { - RKE_TOKEN = random_password.rke2_token.result - SERVER_ADDRESS = hcloud_load_balancer.management_lb.ipv4 + RKE_TOKEN = random_password.rke2_token.result + SERVER_ADDRESS = hcloud_load_balancer.management_lb.ipv4 INSTALL_RKE2_VERSION = var.rke2_version }) @@ -143,7 +143,7 @@ resource "hcloud_server_network" "worker" { } resource "local_file" "name" { - count = var.generate_ssh_key_file ? 1 : 0 + count = var.generate_ssh_key_file ? 1 : 0 content = tls_private_key.machines.private_key_openssh filename = "rancher-host-key" file_permission = "0600" diff --git a/variables.tf b/variables.tf index e07252c..fdf7489 100755 --- a/variables.tf +++ b/variables.tf @@ -31,4 +31,16 @@ variable "additional_lb_service_ports" { type = list(string) default = [] description = "Define additional service ports for the management cluster loadbalancer." +} + +variable "network_zone" { + type = string + default = "eu-central" + description = "Define the network location for the cluster." +} + +variable "node_locations" { + type = list(string) + default = ["hel1", "nbg1", "fsn1"] + description = "Define the location in which nodes will be deployed." } \ No newline at end of file From 59017968aff50d312f79396c769c688f14fb9d05 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 10 Apr 2023 11:43:19 +0200 Subject: [PATCH 2/2] added var comment --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index fdf7489..b704995 100755 --- a/variables.tf +++ b/variables.tf @@ -42,5 +42,5 @@ variable "network_zone" { variable "node_locations" { type = list(string) default = ["hel1", "nbg1", "fsn1"] - description = "Define the location in which nodes will be deployed." + description = "Define the location in which nodes will be deployed. (Most be in the same network zone.)" } \ No newline at end of file