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.
Requirements
No requirements.
Providers
Name | Version |
---|---|
null | n/a |
template | n/a |
Modules
No modules.
Resources
Name | Type |
---|---|
null_resource.default | resource |
template_file.body | data source |
template_file.subject | data source |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
body | Email body template | any | n/a | yes |
enabled | Flag to enable or disable the sending of emails | string | "true" | no |
from | From address for email | any | n/a | yes |
host | SMTP Host | string | "smtp.mailgun.org" | no |
mail_command | Command to execute | string | "email" | no |
password | Password to authenticate with the SMTP server | string | n/a | yes |
port | SMTP Port | string | "587" | no |
subject | Email subject template | any | n/a | yes |
to | Email recipients | list(string) | n/a | yes |
username | Username to authenticate with the SMTP server | string | n/a | yes |
vars | Parameters to pass to the body template | map | {} | no |
Outputs
Name | Description |
---|---|
body | Rendered body of the email |
subject | Rendered subject of the email |