2022-03-03 22:51:42 +00:00
|
|
|
variable "name" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "image" {
|
|
|
|
type = string
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "replicas" {
|
2022-04-13 21:01:14 +00:00
|
|
|
type = number
|
2022-03-03 22:51:42 +00:00
|
|
|
default = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "expose_ports" {
|
2022-04-13 21:01:14 +00:00
|
|
|
type = list(number)
|
2022-03-03 22:51:42 +00:00
|
|
|
default = []
|
|
|
|
}
|
|
|
|
|
|
|
|
variable "host_ports" {
|
|
|
|
type = list(object({
|
2022-04-13 21:01:14 +00:00
|
|
|
host_port = number
|
2022-03-03 22:51:42 +00:00
|
|
|
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 {
|
2022-04-13 21:01:14 +00:00
|
|
|
name = var.name
|
2022-03-03 22:51:42 +00:00
|
|
|
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 {
|
2022-04-13 21:01:14 +00:00
|
|
|
host_port = port.key.host_port
|
2022-03-03 22:51:42 +00:00
|
|
|
container_port = port.key.container_port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|