Skip to content

Commit

Permalink
feat(treafik): add volume driver and driver options to config volume …
Browse files Browse the repository at this point in the history
…and volume mounts
  • Loading branch information
tafaust committed Aug 11, 2024
1 parent b461c41 commit 841277e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions modules/traefik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ No resources.
| <a name="input_secrets"></a> [secrets](#input\_secrets) | (Optional) The secrets to create with and add to the docker container. Creates docker secrets from non-terraform-resources. | <pre>set(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `[]` | no |
| <a name="input_traefik_certificate"></a> [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. | <pre>object({<br> # check https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins<br> driver_name = optional(string, "local"),<br> driver_options = optional(map(string), {})<br> source = optional(string),<br> target = optional(string, "/etc/certificates")<br> type = optional(string, "bind")<br> })</pre> | n/a | yes |
| <a name="input_traefik_config"></a> [traefik\_config](#input\_traefik\_config) | The static config file for traefik. Config can be passed via tftpl or inline string. | `string` | `null` | no |
| <a name="input_traefik_volume_options"></a> [traefik\_volume\_options](#input\_traefik\_volume\_options) | The traefik volume driver with its options. | <pre>object({<br> driver = optional(string, "local")<br> driver_options = optional(map(string), {})<br> })</pre> | `{}` | no |

## Outputs

Expand Down
33 changes: 15 additions & 18 deletions modules/traefik/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -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" {
Expand Down
9 changes: 9 additions & 0 deletions modules/traefik/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 841277e

Please sign in to comment.