From 1549bd6c9d88cd724405c1532e290ff8add387f2 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Sat, 4 Nov 2023 09:49:52 +0100 Subject: [PATCH] Set argocd environment --- terraform/main.tf | 2 +- terraform/modules/k8s-cluster/helm.tf | 4 ++-- terraform/modules/k8s-cluster/main.tf | 4 ++-- terraform/modules/k8s-cluster/manager-node.tf | 6 +++--- terraform/modules/k8s-cluster/variables.tf | 10 ++++++++-- terraform/modules/k8s-cluster/worker-node.tf | 4 ++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 6d1a4a7..b956744 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -46,7 +46,7 @@ module "test_cluster" { network_id = hcloud_network.kubernetes-network.id private_node_ips = ["10.0.0.4", "10.0.0.5", "10.0.0.6"] server_subnet_id = hcloud_network_subnet.k8s-network-subnet.id - cluster_role = "test" + cluster_name = "test" number_nodes = 1 server_type = "cax21" image_name = "ubuntu-22.04" diff --git a/terraform/modules/k8s-cluster/helm.tf b/terraform/modules/k8s-cluster/helm.tf index 8daff5d..b889186 100644 --- a/terraform/modules/k8s-cluster/helm.tf +++ b/terraform/modules/k8s-cluster/helm.tf @@ -47,7 +47,7 @@ resource "null_resource" "install_argocd_single" { inline = [ "helm repo add 2martens https://repo.2martens.de/charts/", "helm install setup 2martens/cluster_setup", - "helm install argocd 2martens/argocd", + "helm install argocd 2martens/argocd --set environment=${var.argocd_environment}", ] } @@ -74,7 +74,7 @@ resource "null_resource" "install_argocd_ha" { inline = [ "helm repo add 2martens https://repo.2martens.de/charts/", "helm install setup 2martens/cluster_setup", - "helm install argocd 2martens/argocd --values /home/terraform/argocd-values-ha.yaml", + "helm install argocd 2martens/argocd --set environment=${var.argocd_environment} --values /home/terraform/argocd-values-ha.yaml", ] } diff --git a/terraform/modules/k8s-cluster/main.tf b/terraform/modules/k8s-cluster/main.tf index 4c4962e..0dd714f 100644 --- a/terraform/modules/k8s-cluster/main.tf +++ b/terraform/modules/k8s-cluster/main.tf @@ -3,14 +3,14 @@ data "hcloud_placement_group" "default" { } locals { - kube_api_server_domain = format("%s.%s.%s", "k8s", var.cluster_role, var.domain) + kube_api_server_domain = format("%s.%s.%s", "k8s", var.cluster_name, var.domain) } resource "hcloud_load_balancer" "kubernetes" { count = var.create_loadbalancer ? 1 : 0 load_balancer_type = var.loadbalancer_type - name = format("%s_%s", "k8s", var.cluster_role) + name = format("%s_%s", "k8s", var.cluster_name) location = var.locations[count.index].name network_zone = var.locations[count.index].network_zone algorithm { diff --git a/terraform/modules/k8s-cluster/manager-node.tf b/terraform/modules/k8s-cluster/manager-node.tf index c54ca60..c2182a7 100644 --- a/terraform/modules/k8s-cluster/manager-node.tf +++ b/terraform/modules/k8s-cluster/manager-node.tf @@ -11,7 +11,7 @@ resource "inwx_nameserver_record" "manager_aaaa" { resource "hcloud_primary_ip" "ipv4_manager_address" { count = var.create_loadbalancer ? 0 : var.number_nodes - name = format("%s_%s_%s_%d", "k8s", var.cluster_role, "ipv4", count.index) + name = format("%s_%s_%s_%d", "k8s", var.cluster_name, "ipv4", count.index) datacenter = element(var.locations.*.datacenter_name, count.index) type = "ipv4" assignee_type = "server" @@ -21,7 +21,7 @@ resource "hcloud_primary_ip" "ipv4_manager_address" { resource "hcloud_primary_ip" "ipv6_manager_address" { count = var.number_nodes - name = format("%s_%s_%s_%d", "k8s", var.cluster_role, "ipv6", count.index) + name = format("%s_%s_%s_%d", "k8s", var.cluster_name, "ipv6", count.index) datacenter = element(var.locations.*.datacenter_name, count.index) type = "ipv6" assignee_type = "server" @@ -39,7 +39,7 @@ resource "hcloud_server_network" "manager_private" { resource "hcloud_server" "manager" { count = var.number_nodes - name = format("%s_%s_%s_%d", "k8s", var.cluster_role, "node", count.index) + name = format("%s_%s_%s_%d", "k8s", var.cluster_name, "node", count.index) image = var.image_name allow_deprecated_images = false server_type = var.server_type diff --git a/terraform/modules/k8s-cluster/variables.tf b/terraform/modules/k8s-cluster/variables.tf index 486230b..d6aa8e0 100644 --- a/terraform/modules/k8s-cluster/variables.tf +++ b/terraform/modules/k8s-cluster/variables.tf @@ -69,8 +69,14 @@ variable "k8s_firewall_id" { type = number } -variable "cluster_role" { - description = "The role the cluster serves. For example test, qs, prod. Will be used for names and subdomains and must be unique within the Hetzner project." +variable "cluster_name" { + description = "The name of the cluster. For example test, qs, prod. Will be used for names and subdomains and must be unique within the Hetzner project (identified by API token)." + type = string + default = "test" +} + +variable "argocd_environment" { + description = "The Argo CD environment to use. Argo CD will install the applications of that environment to the cluster." type = string default = "test" } diff --git a/terraform/modules/k8s-cluster/worker-node.tf b/terraform/modules/k8s-cluster/worker-node.tf index c5f7464..4891d8e 100644 --- a/terraform/modules/k8s-cluster/worker-node.tf +++ b/terraform/modules/k8s-cluster/worker-node.tf @@ -11,7 +11,7 @@ resource "inwx_nameserver_record" "worker_aaaa" { resource "hcloud_primary_ip" "ipv6_worker_address" { count = var.number_worker_nodes - name = format("%s_%s_%s_%d", "k8s", var.cluster_role, "ipv6", count.index) + name = format("%s_%s_%s_%d", "k8s", var.cluster_name, "ipv6", count.index) datacenter = element(var.locations.*.datacenter_name, count.index) type = "ipv6" assignee_type = "server" @@ -29,7 +29,7 @@ resource "hcloud_server_network" "worker_private" { resource "hcloud_server" "worker" { count = var.number_worker_nodes - name = format("%s_%s_%s_%d", "k8s", var.cluster_role, "node", count.index) + name = format("%s_%s_%s_%d", "k8s", var.cluster_name, "node", count.index) image = var.image_name allow_deprecated_images = false server_type = var.server_type