-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.tf
45 lines (35 loc) · 934 Bytes
/
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
data "template_file" "body" {
template = var.body
vars = var.vars
}
data "template_file" "subject" {
template = var.subject
vars = var.vars
}
locals {
body = data.template_file.body.rendered
subject = data.template_file.subject.rendered
command = "${var.mail_command} ${join(" ", var.to)}"
}
resource "null_resource" "default" {
count = var.enabled == "true" ? 1 : 0
triggers = {
subject = "${local.subject}"
body = "${local.body}"
command = "${local.command}"
}
provisioner "local-exec" {
command = local.command
environment {
EMAIL_FROM = var.from
EMAIL_SUBJECT = local.subject
EMAIL_BODY = local.body
EMAIL_PORT = var.port
EMAIL_HOST = var.host
EMAIL_USERNAME = var.username
EMAIL_PASSWORD = var.password
}
on_failure = "fail"
}
depends_on = ["data.template_file.body", "data.template_file.subject"]
}