variable "name" { type = string } variable "image" { type = string } variable "replicas" { type = number default = 1 } variable "expose_ports" { type = list(number) default = [] } variable "host_ports" { type = list(object({ host_port = number container_port = number })) default = [] } resource "kubernetes_deployment" "simple-service" { metadata { name = var.name labels = { app = var.name, } } spec { replicas = var.replicas selector { match_labels = { app = var.name, } } template { metadata { labels = { app = var.name, } } spec { container { name = var.name image = var.image dynamic "port" { for_each = toset(var.expose_ports) content { container_port = port.key } } dynamic "port" { for_each = toset(var.host_ports) content { host_port = port.key.host_port container_port = port.key.container_port } } } } } } }