Unable to add nested block as variable

Hi,
I am trying to pass liveness_probe as a variable . But since liveness_probe is a block inside resource, it doesnt work.
this is the variable i am trying to pass,

and this is the actual resource,

resource "kubernetes_deployment" "k8-deploy" {
  count      = var.enabled == "true" ? 1 : 0
  depends_on = [kubernetes_config_map.env-vars]

  metadata {
    name = var.svc-name

    annotations = {
      dependency = join(" ", list(module.rds-db-migrate.uid))
    }
  }

  spec {
    selector {
      match_labels = {
        service = var.svc-name
      }
    }

    replicas = var.replicas

    template {
      metadata {
        labels = {
          service = var.svc-name
        }
      }

      spec {
        container {
          name  = "${var.svc-name}-container"
          image = "${var.container-image}:${var.svc-version}"

          port {
            container_port = var.svc-port
          }

          liveness_probe  = var.health-check-config
          }
        }
      }
    }
  }

The actual syntax expects something like this liveness_probe { … }

Hi @anilkumarnimisha,

You need to write out the liveness_probe block with the arguments inside it, like this:

  liveness_probe {
    http_get {
      path = var.health_check_config.http_get.path
      port = var.health_check_config.http_get.port
      # ...
    }

    initial_delay_seconds = var.health_check_config.initial_delay_seconds
    period_seconds        = var.health_check_config.period_seconds
  }

If you want your module to treat some of these objects as optional then you can use dynamic blocks to vary the number of blocks based on expressions you write.