diff --git a/core/ingress.tf b/core/ingress.tf index f27f701..a313a75 100644 --- a/core/ingress.tf +++ b/core/ingress.tf @@ -1,8 +1,3 @@ -module "import_output" { - source = "../modules" - hello = "coucou" -} - resource "helm_release" "cert_manager" { name = "cert-manager" repository = "oci://quay.io" diff --git a/core/services.tf b/core/services.tf index 7b00d01..d26ab5f 100644 --- a/core/services.tf +++ b/core/services.tf @@ -1,79 +1,8 @@ -resource "kubernetes_ingress_v1" "automatic_ingress" { - for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true } - metadata { - name = "${each.key}-ingress" - namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) - - annotations = { - "cert-manager.io/cluster-issuer" = "letsencrypt-prod" - "traefik.ingress.kubernetes.io/router.entrypoints" = "websecure" - } - } - - spec { - ingress_class_name = "traefik" - # Dynamic TLS configuration for cert-manager - tls { - hosts = [join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])] - secret_name = "${each.key}-tls-secret" # cert-manager will create and manage this secret automatically - } - - rule { - host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"]) - http { - path { - path = "/" - backend { - service { - name = "${each.key}-svc" - port { - number = each.value.service_port[0] #selecting the first of the list - } - } - } - } - } - } - } +module "ingress" { + source = "../modules/ingress" + kubernetes_input = var.kubernetes } -resource "kubernetes_ingress_v1" "automatic_ingress_legacy" { - for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true && value.legacy_domain == true } - metadata { - name = "${each.key}-ingress-legacy" - namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) - annotations = { - "cert-manager.io/cluster-issuer" = "letsencrypt-prod" - "traefik.ingress.kubernetes.io/router.entrypoints" = "websecure" - } - } - - spec { - ingress_class_name = "traefik" - # Dynamic TLS configuration for cert-manager - tls { - hosts = [join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])] - secret_name = "${each.key}-tryton-tls-secret" # cert-manager will create and manage this secret automatically - } - - rule { - host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"]) - http { - path { - path = "/" - backend { - service { - name = "${each.key}-svc" - port { - number = each.value.service_port[0] #selecting the first of the list - } - } - } - } - } - } - } -} resource "kubernetes_service_v1" "automatic_service" { for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true && value.docker != true } diff --git a/modules/ingress.tf b/modules/ingress.tf deleted file mode 100644 index a715541..0000000 --- a/modules/ingress.tf +++ /dev/null @@ -1,14 +0,0 @@ -variable "hello" { - type = string -} - -output "instance_id" { - description = "ID of the EC2 instance" - value = var.hello -} - -resource "null_resource" "test_module_linkage" { - triggers = { - passed_value = var.hello - } -} diff --git a/modules/ingress/ingress.tf b/modules/ingress/ingress.tf new file mode 100644 index 0000000..b1b22b6 --- /dev/null +++ b/modules/ingress/ingress.tf @@ -0,0 +1,136 @@ +variable "kubernetes_input" { + type = map(object({ + name = optional(string) + docker = optional(bool) + image = string + pvc = optional(map(object({ + name = optional(string) + config_map = optional(bool, false) + secret = optional(bool, false) + local_path = optional(bool, false) + host_path = optional(string) + storage_class_name = optional(string, "nfs-storage-intelligent") + annotations_fileType = optional(string) + mount_path = string + sub_path = optional(string) + }))) + environment = optional(map(object({ + name = optional(string) + value = optional(string) + value_from = optional(object({ + secret_key_ref = object({ + name = string + key = optional(string, null) + }) + })) + }))) + replicas = optional(number, 1) + namespace = optional(string) + connected_namespace = optional(string, "") + command = optional(list(string)) + service_port = optional(list(number)) + external_port = optional(bool, false) + service_type = optional(string, "ClusterIP") + service_name = optional(string) + domain_name = optional(string) + legacy_domain = optional(bool, false) + exposed = optional(bool, true) + liveness_tcp_socket = optional(number) + liveness_http_get = optional(string) + liveness_http_get_path = optional(string) + database = optional(map(string)) + database_command = optional(list(string)) + database_args = optional(list(string)) + redis = optional(map(string)) + enabled = optional(bool, true) + secret_ref = optional(list(string)) + config_map_ref = optional(list(string)) + config_map_import = optional(list(string)) + secret_import = optional(list(string)) + extra_manifest = optional(list(string)) + requirements = optional(map(string)) + dns_nameservers = optional(string) + service_account_name = optional(string) + environment_variables = optional(map(string), { name = "value" }) + security_context = optional(bool, false) + })) + +} + + +resource "kubernetes_ingress_v1" "automatic_ingress" { + for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true } + metadata { + name = "${each.key}-ingress" + namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) + + annotations = { + "cert-manager.io/cluster-issuer" = "letsencrypt-prod" + "traefik.ingress.kubernetes.io/router.entrypoints" = "websecure" + } + } + + spec { + ingress_class_name = "traefik" + # Dynamic TLS configuration for cert-manager + tls { + hosts = [join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])] + secret_name = "${each.key}-tls-secret" # cert-manager will create and manage this secret automatically + } + + rule { + host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"]) + http { + path { + path = "/" + backend { + service { + name = "${each.key}-svc" + port { + number = each.value.service_port[0] #selecting the first of the list + } + } + } + } + } + } + } +} +resource "kubernetes_ingress_v1" "automatic_ingress_legacy" { + for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true && value.legacy_domain == true } + metadata { + name = "${each.key}-ingress-legacy" + namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) + + annotations = { + "cert-manager.io/cluster-issuer" = "letsencrypt-prod" + "traefik.ingress.kubernetes.io/router.entrypoints" = "websecure" + } + } + + spec { + ingress_class_name = "traefik" + # Dynamic TLS configuration for cert-manager + tls { + hosts = [join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])] + secret_name = "${each.key}-tryton-tls-secret" # cert-manager will create and manage this secret automatically + } + + rule { + host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"]) + http { + path { + path = "/" + backend { + service { + name = "${each.key}-svc" + port { + number = each.value.service_port[0] #selecting the first of the list + } + } + } + } + } + } + } +} \ No newline at end of file