feat(docker-service): enable custom pguid & uid and extra hosts

This commit is contained in:
Yuris Cakranegara
2025-06-09 00:11:27 +10:00
parent 88f171425b
commit 27ce999c97
2 changed files with 34 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ module "system_globals" {
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
}
dotenv = {
source = "germanbrew/dotenv"
@@ -22,8 +22,8 @@ locals {
default_env_vars = {
TZ = module.system_globals.timezone
PUID = module.system_globals.puid
PGID = module.system_globals.pgid
PUID = var.puid != null ? var.puid : module.system_globals.puid
PGID = var.pgid != null ? var.pgid : module.system_globals.pgid
}
env_vars = merge(var.env_vars, local.default_env_vars)
@@ -71,6 +71,15 @@ resource "docker_container" "service_container" {
# Set the network mode (bridge, host, etc.)
network_mode = local.network_mode
# Add host mappings (entries for /etc/hosts)
dynamic "host" {
for_each = var.host_mappings
content {
host = host.value.host
ip = host.value.ip
}
}
# Dynamically configure ports based on the provided list
dynamic "ports" {

View File

@@ -65,6 +65,18 @@ variable "env_vars" {
sensitive = true
}
variable "puid" {
description = "User ID for the container"
type = number
default = null
}
variable "pgid" {
description = "Group ID for the container"
type = number
default = null
}
variable "labels" {
description = "Docker container labels"
type = map(string)
@@ -77,13 +89,22 @@ variable "monitoring" {
default = true
}
variable "host_mappings" {
description = "Additional host mappings for the container (/etc/hosts entries)"
type = list(object({
host = string
ip = string
}))
default = []
}
variable "healthcheck" {
description = "Container healthcheck configuration"
type = object({
test = list(string)
interval = string
timeout = string
start_period = string
start_period = optional(string)
retries = number
})
default = null