diff --git a/main.tf b/main.tf index 057a31c..9a23a55 100644 --- a/main.tf +++ b/main.tf @@ -1,11 +1,13 @@ resource "kubernetes_deployment" "this" { wait_for_rollout = var.wait_for_rollout - + metadata { name = var.name namespace = var.namespace } + depends_on = [var.namespace] + spec { replicas = var.replicas @@ -50,13 +52,13 @@ resource "kubernetes_deployment" "this" { lifecycle { pre_stop { exec { - command = [ "sleep", var.pre_stop_sleep_seconds ] + command = ["sleep", var.pre_stop_sleep_seconds] } } } dynamic "liveness_probe" { - for_each = var.liveness_probe == null || var.disable_liveness_probe ? [ ] : [ var.liveness_probe ] + for_each = var.liveness_probe == null || var.disable_liveness_probe ? [] : [var.liveness_probe] content { http_get { path = liveness_probe.value["path"] @@ -77,7 +79,7 @@ resource "kubernetes_deployment" "this" { } dynamic "startup_probe" { - for_each = var.startup_probe == null || var.disable_startup_probe ? [ ] : [ var.startup_probe ] + for_each = var.startup_probe == null || var.disable_startup_probe ? [] : [var.startup_probe] content { http_get { path = startup_probe.value["path"] @@ -134,6 +136,8 @@ resource "kubernetes_service" "this" { namespace = var.namespace } + depends_on = [var.namespace, kubernetes_deployment.this] + spec { type = var.service_type @@ -168,6 +172,13 @@ resource "kubernetes_ingress" "this" { } } + depends_on = [ + var.namespace, + kubernetes_deployment.this, + kubernetes_service.this, + kubernetes_ingress.this + ] + spec { rule { host = var.host diff --git a/variables.tf b/variables.tf index ff90e25..8b7ffe5 100644 --- a/variables.tf +++ b/variables.tf @@ -1,12 +1,12 @@ variable "cpu_limit" { description = "The maximum CPU. Format is Xm, which is X thousandths of a CPU, e.g. 2000m would be 2 CPUs. The default is 2 CPUs. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/" - default = "2000m" + default = "2000m" } variable "cpu_request" { description = "The amount of CPU to request. Format is Xm, which represent X thousandths of a CPU, e.g. 500m would be half a CPU. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/" - default = 0 + default = 0 } variable "host" { @@ -30,7 +30,7 @@ variable "image" { variable "liveness_probe" { description = "The URL to use in the app's liveness probe." - type = object({ + type = object({ failure_threshold = number frequency = number initial_delay = number @@ -43,12 +43,12 @@ variable "liveness_probe" { variable "mem_limit" { description = "The maximum amount of memory to reserve. Default is 8Gi. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/" - default = "8Gi" + default = "8Gi" } variable "mem_request" { description = "The amount of memory to request. https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/" - default = 0 + default = 0 } variable "name" { @@ -83,7 +83,7 @@ variable "service_type" { variable "startup_probe" { description = "Configuration for the app's startup probe, if any." - type = object({ + type = object({ failure_threshold = number frequency = number initial_delay = number