Add mailcow to terraform

This commit is contained in:
Tobias Reisinger 2024-10-29 22:43:05 +01:00
parent d73462cd90
commit f20b2596d0
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
18 changed files with 135 additions and 35 deletions

View file

@ -0,0 +1,17 @@
resource "random_password" "mailcow_service_passwords" {
for_each = local.services_mail
length = 32
special = false
}
resource "mailcow_mailbox" "services" {
for_each = local.services_mail
domain = "serguzim.me"
full_name = each.value.mail
local_part = each.value.mail
password = random_password.mailcow_service_passwords[each.key].result
imap_access = false
pop3_access = false
sogo_access = false
quota = 128
}

View file

@ -4,6 +4,10 @@ terraform {
source = "goauthentik/authentik"
version = "~> 2024.8.0"
}
mailcow = {
source = "l-with/mailcow"
version = "~> 0.7.5"
}
postgresql = {
source = "cyrilgdn/postgresql"
version = "~> 1.23.0"
@ -15,4 +19,5 @@ locals {
services_auth = {for key, val in var.services : key => val if val.auth}
services_database = {for key, val in var.services : key => val if val.database}
services_s3 = {for key, val in var.services : key => val if val.s3}
services_mail = {for key, val in var.services : key => val if val.mail != null}
}

View file

@ -19,3 +19,13 @@ output "postgresql_data" {
}
sensitive = true
}
output "mailcow_data" {
value = {
for key in keys(mailcow_mailbox.services) : key => {
"address" = mailcow_mailbox.services[key].address
"password" = mailcow_mailbox.services[key].password
}
}
sensitive = true
}

View file

@ -18,5 +18,6 @@ variable "services" {
auth_redirects = optional(list(string))
s3 = bool
database = bool
mail = optional(string)
}))
}