Module: smtp-mail
Terraform Module to send emails using an SMTP server by calling an external email
command.
Introduction
This terraform module uses an external command using the local-exec
provisioner to send emails. It's ideally suited for sending transactional emails
related to the apply
phase. For example, notifying a user of their IAM user account getting created or the deployment of a new ECS application.
NOTE: The null
refers to the primary Terraform provider used in this module.
Dependencies
First install the latest release of the email
cli tool here: https://github.com/wrouesnel/emailcli/releases
Make sure it exists in your PATH
(E.g. /usr/local/bin
)
We distribute an Alpine Linux package (emailcli
) as part of our toolchain.
curl -sSL https://apk.cloudposse.com/install.sh | sudo bash
apk add emailcli@cloudposse
Usage
module "welcome" {
source = "git::https://github.com/cloudposse/terraform-null-smtp-mail.git?ref=master"
host = "smtp.mailgun.org"
port = "587"
username = "[email protected]"
password = "changeme"
from = "[email protected]"
to = ["[email protected]"]
subject = "Welcome $${first_name}"
body = "Your account has been created. Login here: $${homepage}"
vars = {
first_name = "Example"
homepage = "https://cloudposse.com"
}
}
NOTE: Use the file(...)
interpolation function to use a template file.
Variables
Required Variables
body
(any
) requiredEmail body template
from
(any
) requiredFrom address for email
password
(string
) requiredPassword to authenticate with the SMTP server
subject
(any
) requiredEmail subject template
to
(list(string)
) requiredEmail recipients
username
(string
) requiredUsername to authenticate with the SMTP server
Optional Variables
host
(string
) optionalSMTP Host
Default value:
"smtp.mailgun.org"
mail_command
(string
) optionalCommand to execute
Default value:
"email"
port
(string
) optionalSMTP Port
Default value:
"587"
vars
(map
) optionalParameters to pass to the body template
Default value:
{ }
Context Variables
The following variables are defined in the context.tf
file of this module and part of the terraform-null-label pattern.
context.tf
file of this module and part of the terraform-null-label pattern.enabled
(string
) optionalFlag to enable or disable the sending of emails
Required: NoDefault value:
"true"
Outputs
Dependencies
Providers
null
template
Resources
The following resources are used by this module:
null_resource.default
(resource)
Data Sources
The following data sources are used by this module:
template_file.body
(data source)template_file.subject
(data source)