-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
66 lines (57 loc) · 1.58 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
data "template_file" "body" {
template = "${var.body}"
vars = "${var.vars}"
}
data "template_file" "subject" {
template = "${var.subject}"
vars = "${var.vars}"
}
resource "random_uuid" "body_file" {}
locals {
body = "${data.template_file.body.rendered}"
body_file = random_uuid.body_file.result
subject = "${data.template_file.subject.rendered}"
command = "${var.mail_command} -s \"${local.subject}\" -F ${path.module}/.muttrc ${join(" ",[for a in toset(var.attachments): "-a ${a}"])} -i ${path.module}/body/${local.body_file} -- ${join(",",var.to)} "
}
resource "local_file" "default" {
content = <<EOT
set from = "${var.from}"
set smtp_url = "${var.smtp_url}"
set smtp_pass = "${var.password}"
EOT
filename = "${path.module}/.muttrc"
}
resource "local_file" "body" {
content = local.body
filename = "${path.module}/body/${local.body_file}"
}
resource "null_resource" "install" {
count = "${var.mail_install == "true" ? 1 : 0}"
provisioner "local-exec" {
command = "apt install ${var.mail_command} -y"
interpreter = ["bash", "-c"]
}
triggers = {
always = timestamp()
}
}
resource "null_resource" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
triggers = {
subject = "${local.subject}"
body = "${local.body}"
to = join(",",var.to)
command = "${local.command}"
}
provisioner "local-exec" {
command = "${local.command}"
interpreter = ["bash", "-c"]
}
depends_on = [
data.template_file.body,
data.template_file.subject,
local_file.body,
local_file.default,
null_resource.install
]
}