Mqtt as a module.
This commit is contained in:
parent
94e1e630fe
commit
e63eedc370
6 changed files with 113 additions and 0 deletions
45
products/mqtt/inputs.tf
Normal file
45
products/mqtt/inputs.tf
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
variable "stack_name" {
|
||||||
|
default = "mqtt"
|
||||||
|
type = string
|
||||||
|
description = "The name of the stack to create."
|
||||||
|
}
|
||||||
|
variable "networks" {
|
||||||
|
type = list(object({
|
||||||
|
name = string
|
||||||
|
id = string
|
||||||
|
}))
|
||||||
|
default = []
|
||||||
|
description = "A list of network names to attach the service to."
|
||||||
|
}
|
||||||
|
variable "traefik" {
|
||||||
|
default = null
|
||||||
|
type = object({
|
||||||
|
domain = string
|
||||||
|
port = optional(number)
|
||||||
|
non-ssl = optional(bool, true)
|
||||||
|
ssl = optional(bool, false)
|
||||||
|
rule = optional(string)
|
||||||
|
middlewares = optional(list(string))
|
||||||
|
network = optional(object({ name = string, id = string }))
|
||||||
|
basic-auth-users = optional(list(string))
|
||||||
|
})
|
||||||
|
description = "Whether to enable traefik for the service."
|
||||||
|
}
|
||||||
|
variable "placement_constraints" {
|
||||||
|
default = []
|
||||||
|
type = list(string)
|
||||||
|
description = "Docker Swarm placement constraints"
|
||||||
|
}
|
||||||
|
variable "mounts" {
|
||||||
|
type = map(string)
|
||||||
|
default = {}
|
||||||
|
description = "A map of host paths to container paths to mount. The key is the host path, and the value is the container path."
|
||||||
|
}
|
||||||
|
variable "ports" {
|
||||||
|
type = list(object({
|
||||||
|
host = optional(number, null)
|
||||||
|
container = number
|
||||||
|
protocol = optional(string, "tcp")
|
||||||
|
}))
|
||||||
|
default = []
|
||||||
|
}
|
16
products/mqtt/mosquitto.conf
Normal file
16
products/mqtt/mosquitto.conf
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
listener 1883 0.0.0.0
|
||||||
|
socket_domain ipv4
|
||||||
|
|
||||||
|
pid_file /tmp/mosquitto.pid
|
||||||
|
|
||||||
|
persistence true
|
||||||
|
persistence_location /mosquitto/data/
|
||||||
|
|
||||||
|
log_dest file /mosquitto/logs/mosquitto.log
|
||||||
|
log_dest stdout
|
||||||
|
|
||||||
|
#password_file /mosquitto/config/mosquitto.passwd
|
||||||
|
allow_anonymous true
|
||||||
|
|
||||||
|
listener 8080 127.0.0.1
|
||||||
|
protocol websockets
|
19
products/mqtt/mqtt.tf
Normal file
19
products/mqtt/mqtt.tf
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
module "service" {
|
||||||
|
source = "../../docker/service"
|
||||||
|
image = "eclipse-mosquitto:latest"
|
||||||
|
service_name = "mqtt"
|
||||||
|
stack_name = var.stack_name
|
||||||
|
networks = concat(var.networks, [module.network.network])
|
||||||
|
traefik = var.traefik
|
||||||
|
placement_constraints = var.placement_constraints
|
||||||
|
mounts = var.mounts
|
||||||
|
ports = var.ports
|
||||||
|
configs = {
|
||||||
|
"/mosquitto/config/mosquitto.conf" = templatefile("${path.module}/mosquitto.conf", {})
|
||||||
|
}
|
||||||
|
volumes = {
|
||||||
|
"mqtt_data" = "/mosquitto/data"
|
||||||
|
"mqtt_logs" = "/mosquitto/logs"
|
||||||
|
}
|
||||||
|
converge_enable = false
|
||||||
|
}
|
4
products/mqtt/network.tf
Normal file
4
products/mqtt/network.tf
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module "network" {
|
||||||
|
source = "../../docker/network"
|
||||||
|
stack_name = var.stack_name
|
||||||
|
}
|
9
products/mqtt/outputs.tf
Normal file
9
products/mqtt/outputs.tf
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
output "docker_service" {
|
||||||
|
value = module.service.docker_service
|
||||||
|
}
|
||||||
|
output "network" {
|
||||||
|
value = module.network.network
|
||||||
|
}
|
||||||
|
output "endpoint" {
|
||||||
|
value = replace(module.service.endpoint, "http://", "mqtt://")
|
||||||
|
}
|
20
products/mqtt/terraform.tf
Normal file
20
products/mqtt/terraform.tf
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
terraform {
|
||||||
|
required_version = "~> 1.6"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
docker = {
|
||||||
|
source = "kreuzwerker/docker"
|
||||||
|
version = "~> 3.0"
|
||||||
|
}
|
||||||
|
random = {
|
||||||
|
source = "hashicorp/random"
|
||||||
|
version = "~> 3.5"
|
||||||
|
}
|
||||||
|
htpasswd = {
|
||||||
|
source = "loafoe/htpasswd"
|
||||||
|
version = "~> 1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue