From 841277e168a9eee024711432301932db99df861b Mon Sep 17 00:00:00 2001 From: Thomas Faust Date: Sun, 11 Aug 2024 21:36:39 +0200 Subject: [PATCH] feat(treafik): add volume driver and driver options to config volume and volume mounts --- modules/traefik/README.md | 1 + modules/traefik/main.tf | 33 +++++++++++++++------------------ modules/traefik/variables.tf | 9 +++++++++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/modules/traefik/README.md b/modules/traefik/README.md index 2172fe0..5887ff0 100644 --- a/modules/traefik/README.md +++ b/modules/traefik/README.md @@ -49,6 +49,7 @@ No resources. | [secrets](#input\_secrets) | (Optional) The secrets to create with and add to the docker container. Creates docker secrets from non-terraform-resources. |
set(object({
file_name = string
# secret_id = string # secret will be created and we take that resource id
file_gid = optional(string, "0")
file_mode = optional(number, 0444)
file_uid = optional(string, "0")
secret_name = optional(string, null)
secret_data = string
}))
| `[]` | no | | [traefik\_certificate](#input\_traefik\_certificate) | Configuration settings for a Docker volume used by Traefik to manage SSL certificates. The 'driver' field allows for driver-specific options in a map format. The 'source' field specifies the path or identifier of the volume source. The 'target' field defines the destination path within the container, defaulting to '/etc/certificates'. The 'type' field indicates the mount type, with 'bind' as the default. |
object({
# check https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins
driver_name = optional(string, "local"),
driver_options = optional(map(string), {})
source = optional(string),
target = optional(string, "/etc/certificates")
type = optional(string, "bind")
})
| n/a | yes | | [traefik\_config](#input\_traefik\_config) | The static config file for traefik. Config can be passed via tftpl or inline string. | `string` | `null` | no | +| [traefik\_volume\_options](#input\_traefik\_volume\_options) | The traefik volume driver with its options. |
object({
driver = optional(string, "local")
driver_options = optional(map(string), {})
})
| `{}` | no | ## Outputs diff --git a/modules/traefik/main.tf b/modules/traefik/main.tf index 69815b5..3f33308 100644 --- a/modules/traefik/main.tf +++ b/modules/traefik/main.tf @@ -22,26 +22,21 @@ locals { read_only = false tmpfs_options = {} volume_options = { - driver_name = var.traefik_certificate.driver_name - driver_options = var.traefik_certificate.driver_options + driver_name = coalesce(var.traefik_certificate.driver_name, var.traefik_volume_options.driver) + driver_options = coalesce(var.traefik_certificate.driver_options, var.traefik_volume_options.driver_options) } }, { - target = "/etc/traefik" - source = module.traefik_docker_volume.this.name - type = "volume" - read_only = false - tmpfs_options = {} - volume_options = {} + target = "/etc/traefik" + source = module.traefik_docker_volume.this.name + type = "volume" + read_only = false + tmpfs_options = {} + volume_options = { + driver_name = var.traefik_volume_options.driver + driver_options = var.traefik_volume_options.driver_options + } } - # { - # target = "/etc/certificates" - # source = local.certificate.source - # type = local.certificate.type - # volume_options = { - # driver_options = var.certificate.driver - # } - # } ], tolist(var.mounts) ) @@ -79,8 +74,10 @@ locals { module "traefik_docker_volume" { source = "github.com/ehwplus/terraswarm//modules/base_docker_volume?ref=main" - name = local.name - namespace = local.namespace + name = local.name + namespace = local.namespace + driver = var.traefik_volume_options.driver + driver_options = var.traefik_volume_options.driver_options } module "traefik_docker_service" { diff --git a/modules/traefik/variables.tf b/modules/traefik/variables.tf index adaf01e..c7a845b 100644 --- a/modules/traefik/variables.tf +++ b/modules/traefik/variables.tf @@ -337,6 +337,15 @@ variable "healthcheck" { # Traefik ################################################################################ +variable "traefik_volume_options" { + type = object({ + driver = optional(string, "local") + driver_options = optional(map(string), {}) + }) + description = "The traefik volume driver with its options." + default = {} +} + variable "traefik_config" { type = string description = "The static config file for traefik. Config can be passed via tftpl or inline string."