Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Commit d529477

Browse files
authored
Send emails from Terraform (#1)
* Send emails from Terraform * Update readme * Update instructions * Update example * Add README.yaml * trigger build * trigger build * Fix readme * fix formatting
1 parent 5587eac commit d529477

File tree

14 files changed

+570
-2
lines changed

14 files changed

+570
-2
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Compiled files
2+
*.tfstate
3+
*.tfstate.backup
4+
5+
# Module directory
6+
.terraform/
7+
.idea
8+
*.iml
9+
10+
.build-harness
11+
build-harness

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
addons:
2+
apt:
3+
packages:
4+
- git
5+
- make
6+
- curl
7+
8+
install:
9+
- make init
10+
11+
script:
12+
- make terraform/install
13+
- make terraform/get-plugins
14+
- make terraform/get-modules
15+
- make terraform/lint
16+
- make terraform/validate

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SHELL := /bin/bash
2+
3+
# List of targets the `readme` target should call before generating the readme
4+
export README_DEPS ?= docs/targets.md docs/terraform.md
5+
6+
-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
7+
8+
## Lint terraform code
9+
lint:
10+
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate

README.md

Lines changed: 246 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,246 @@
1-
# terraform-null-smtp-mail
2-
Terraform module to send email via an SMTP server
1+
<!-- This file was automatically generated by the `build-harness`. Make all changes to `README.yaml` and run `make readme` to rebuild this file. -->
2+
3+
4+
[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com)
5+
6+
# terraform-null-smtp-mail [![Build Status](https://travis-ci.org/cloudposse/terraform-null-smtp-mail.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-null-smtp-mail) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-null-smtp-mail.svg)](https://github.com/cloudposse/terraform-null-smtp-mail/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
7+
8+
9+
Terraform Module to send emails using an SMTP server by calling an external `email` command.
10+
11+
12+
---
13+
14+
This project is part of our comprehensive ["SweetOps"](https://docs.cloudposse.com) approach towards DevOps.
15+
16+
17+
It's 100% Open Source and licensed under the [APACHE2](LICENSE).
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
## Introduction
28+
29+
This terraform module uses an external command using the [`local-exec`](https://www.terraform.io/docs/provisioners/local-exec.html) provisioner to send emails. It's ideally suited for sending transactional emails
30+
related to the `apply` phase. For example, notifying a user of their [IAM user account](https://github.com/cloudposse/terraform-aws-iam-user) getting created or the deployment of a new [ECS application](https://github.com/cloudposse/terraform-aws-ecs-web-app).
31+
32+
**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
33+
34+
## Dependencies
35+
36+
First install the latest release of the `email` cli tool here: https://github.com/wrouesnel/emailcli/releases
37+
38+
Make sure it exists in your `PATH` (E.g. `/usr/local/bin`)
39+
40+
We distribute an Alpine Linux package (`emailcli`) as part of our [toolchain](https://github.com/cloudposse/packages).
41+
42+
```
43+
curl -sSL https://apk.cloudposse.com/install.sh | sudo bash
44+
apk add emailcli@cloudposse
45+
```
46+
47+
## Usage
48+
49+
50+
```hcl
51+
module "welcome" {
52+
source = "git::https://github.com/cloudposse/terraform-null-smtp-mail.git?ref=master"
53+
host = "smtp.mailgun.org"
54+
port = "587"
55+
username = "postmaster@ourdomain.com"
56+
password = "changeme"
57+
from = "admin@yourdomain.com"
58+
to = ["example@yourdomain.com"]
59+
subject = "Welcome $${first_name}"
60+
body = "Your account has been created. Login here: $${homepage}"
61+
62+
vars = {
63+
first_name = "Example"
64+
homepage = "https://cloudposse.com"
65+
}
66+
}
67+
```
68+
69+
__NOTE:__ Use the `file(...)` interpolation function to use a template file.
70+
71+
72+
73+
74+
75+
76+
## Makefile Targets
77+
```
78+
Available targets:
79+
80+
help Help screen
81+
help/all Display help for all targets
82+
help/short This help short screen
83+
lint Lint terraform code
84+
85+
```
86+
87+
## Inputs
88+
89+
| Name | Description | Type | Default | Required |
90+
|------|-------------|:----:|:-----:|:-----:|
91+
| body | Email body template | string | - | yes |
92+
| enabled | Flag to enable or disable the sending of emails | string | `true` | no |
93+
| from | From address for email | string | - | yes |
94+
| host | SMTP Host | string | `smtp.mailgun.org` | no |
95+
| mail_command | Command to execute | string | `email` | no |
96+
| password | Password to authenticate with the SMTP server | string | - | yes |
97+
| port | SMTP Port | string | `587` | no |
98+
| subject | Email subject template | string | - | yes |
99+
| to | Email recipients | list | - | yes |
100+
| username | Username to authenticate with the SMTP server | string | - | yes |
101+
| vars | Parameters to pass to the body template | string | `<map>` | no |
102+
103+
## Outputs
104+
105+
| Name | Description |
106+
|------|-------------|
107+
| body | Rendered body of the email |
108+
| subject | Rendered subject of the email |
109+
110+
111+
112+
113+
## Related Projects
114+
115+
Check out these related projects.
116+
117+
- [emailcli](https://github.com/wrouesnel/emailcli) - 12-factor compatible command line tool for sending emails that is written in Go.
118+
119+
120+
121+
## Help
122+
123+
**Got a question?**
124+
125+
File a GitHub [issue](https://github.com/cloudposse/terraform-null-smtp-mail/issues), send us an [email][email] or join our [Slack Community][slack].
126+
127+
## Commercial Support
128+
129+
Work directly with our team of DevOps experts via email, slack, and video conferencing.
130+
131+
We provide [*commercial support*][commercial_support] for all of our [Open Source][github] projects. As a *Dedicated Support* customer, you have access to our team of subject matter experts at a fraction of the cost of a full-time engineer.
132+
133+
[![E-Mail](https://img.shields.io/badge/email-hello@cloudposse.com-blue.svg)](mailto:hello@cloudposse.com)
134+
135+
- **Questions.** We'll use a Shared Slack channel between your team and ours.
136+
- **Troubleshooting.** We'll help you triage why things aren't working.
137+
- **Code Reviews.** We'll review your Pull Requests and provide constructive feedback.
138+
- **Bug Fixes.** We'll rapidly work to fix any bugs in our projects.
139+
- **Build New Terraform Modules.** We'll develop original modules to provision infrastructure.
140+
- **Cloud Architecture.** We'll assist with your cloud strategy and design.
141+
- **Implementation.** We'll provide hands-on support to implement our reference architectures.
142+
143+
144+
## Community Forum
145+
146+
Get access to our [Open Source Community Forum][slack] on Slack. It's **FREE** to join for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build *sweet* infrastructure.
147+
148+
## Contributing
149+
150+
### Bug Reports & Feature Requests
151+
152+
Please use the [issue tracker](https://github.com/cloudposse/terraform-null-smtp-mail/issues) to report any bugs or file feature requests.
153+
154+
### Developing
155+
156+
If you are interested in being a contributor and want to get involved in developing this project or [help out](https://github.com/orgs/cloudposse/projects/3) with our other projects, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com).
157+
158+
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
159+
160+
1. **Fork** the repo on GitHub
161+
2. **Clone** the project to your own machine
162+
3. **Commit** changes to your own branch
163+
4. **Push** your work back up to your fork
164+
5. Submit a **Pull Request** so that we can review your changes
165+
166+
**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
167+
168+
169+
## Copyright
170+
171+
Copyright © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com)
172+
173+
174+
175+
## License
176+
177+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
178+
179+
See [LICENSE](LICENSE) for full details.
180+
181+
Licensed to the Apache Software Foundation (ASF) under one
182+
or more contributor license agreements. See the NOTICE file
183+
distributed with this work for additional information
184+
regarding copyright ownership. The ASF licenses this file
185+
to you under the Apache License, Version 2.0 (the
186+
"License"); you may not use this file except in compliance
187+
with the License. You may obtain a copy of the License at
188+
189+
https://www.apache.org/licenses/LICENSE-2.0
190+
191+
Unless required by applicable law or agreed to in writing,
192+
software distributed under the License is distributed on an
193+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
194+
KIND, either express or implied. See the License for the
195+
specific language governing permissions and limitations
196+
under the License.
197+
198+
199+
200+
201+
202+
203+
204+
205+
206+
## Trademarks
207+
208+
All other trademarks referenced herein are the property of their respective owners.
209+
210+
## About
211+
212+
This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at <hello@cloudposse.com>
213+
214+
[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com)
215+
216+
We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We love [Open Source Software](https://github.com/cloudposse/)!
217+
218+
We offer paid support on all of our projects.
219+
220+
Check out [our other projects][github], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.
221+
222+
[docs]: https://docs.cloudposse.com/
223+
[website]: https://cloudposse.com/
224+
[github]: https://github.com/cloudposse/
225+
[commercial_support]: https://github.com/orgs/cloudposse/projects
226+
[jobs]: https://cloudposse.com/jobs/
227+
[hire]: https://cloudposse.com/contact/
228+
[slack]: https://slack.cloudposse.com/
229+
[linkedin]: https://www.linkedin.com/company/cloudposse
230+
[twitter]: https://twitter.com/cloudposse/
231+
[email]: mailto:hello@cloudposse.com
232+
233+
234+
### Contributors
235+
236+
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
237+
|---|---|---|
238+
239+
[osterman_homepage]: https://github.com/osterman
240+
[osterman_avatar]: https://github.com/osterman.png?size=150
241+
[goruha_homepage]: https://github.com/goruha
242+
[goruha_avatar]: https://github.com/goruha.png?size=150
243+
[aknysh_homepage]: https://github.com/aknysh
244+
[aknysh_avatar]: https://github.com/aknysh.png?size=150
245+
246+

README.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
#
3+
# This is the canonical configuration for the `README.md`
4+
# Run `make readme` to rebuild the `README.md`
5+
#
6+
7+
# Name of this project
8+
name: terraform-null-smtp-mail
9+
10+
# License of this project
11+
license: "APACHE2"
12+
13+
# Canonical GitHub repo
14+
github_repo: cloudposse/terraform-null-smtp-mail
15+
16+
# Badges to display
17+
badges:
18+
- name: "Build Status"
19+
image: "https://travis-ci.org/cloudposse/terraform-null-smtp-mail.svg?branch=master"
20+
url: "https://travis-ci.org/cloudposse/terraform-null-smtp-mail"
21+
- name: "Latest Release"
22+
image: "https://img.shields.io/github/release/cloudposse/terraform-null-smtp-mail.svg"
23+
url: "https://github.com/cloudposse/terraform-null-smtp-mail/releases/latest"
24+
- name: "Slack Community"
25+
image: "https://slack.cloudposse.com/badge.svg"
26+
url: "https://slack.cloudposse.com"
27+
28+
related:
29+
- name: "terraform-aws-iam-user"
30+
description: "Terraform module to provision an IAM user account for humans and associate it with IAM groups"
31+
url: "https://github.com/cloudposse/terraform-aws-iam-user"
32+
33+
related:
34+
- name: "emailcli"
35+
description: "12-factor compatible command line tool for sending emails that is written in Go."
36+
url: "https://github.com/wrouesnel/emailcli"
37+
38+
39+
# Short description of this project
40+
description: |-
41+
Terraform Module to send emails using an SMTP server by calling an external `email` command.
42+
43+
introduction: |-
44+
This terraform module uses an external command using the [`local-exec`](https://www.terraform.io/docs/provisioners/local-exec.html) provisioner to send emails. It's ideally suited for sending transactional emails
45+
related to the `apply` phase. For example, notifying a user of their [IAM user account](https://github.com/cloudposse/terraform-aws-iam-user) getting created or the deployment of a new [ECS application](https://github.com/cloudposse/terraform-aws-ecs-web-app).
46+
47+
**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
48+
49+
## Dependencies
50+
51+
First install the latest release of the `email` cli tool here: https://github.com/wrouesnel/emailcli/releases
52+
53+
Make sure it exists in your `PATH` (E.g. `/usr/local/bin`)
54+
55+
We distribute an Alpine Linux package (`emailcli`) as part of our [toolchain](https://github.com/cloudposse/packages).
56+
57+
```
58+
curl -sSL https://apk.cloudposse.com/install.sh | sudo bash
59+
apk add emailcli@cloudposse
60+
```
61+
62+
# How to use this project
63+
usage: |-
64+
65+
```hcl
66+
module "welcome" {
67+
source = "git::https://github.com/cloudposse/terraform-null-smtp-mail.git?ref=master"
68+
host = "smtp.mailgun.org"
69+
port = "587"
70+
username = "postmaster@ourdomain.com"
71+
password = "changeme"
72+
from = "admin@yourdomain.com"
73+
to = ["example@yourdomain.com"]
74+
subject = "Welcome $${first_name}"
75+
body = "Your account has been created. Login here: $${homepage}"
76+
77+
vars = {
78+
first_name = "Example"
79+
homepage = "https://cloudposse.com"
80+
}
81+
}
82+
```
83+
84+
__NOTE:__ Use the `file(...)` interpolation function to use a template file.
85+
86+
include:
87+
- "docs/targets.md"
88+
- "docs/terraform.md"
89+
90+
# Contributors to this project
91+
contributors:
92+
- name: "Erik Osterman"
93+
github: "osterman"
94+
- name: "Igor Rodionov"
95+
github: "goruha"
96+
- name: "Andriy Knysh"
97+
github: "aknysh"
98+

0 commit comments

Comments
 (0)