Skip to content

Commit

Permalink
Merge pull request #5 from samstav/rename-to-terraform-mailgun-aws
Browse files Browse the repository at this point in the history
Rename to terraform-mailgun-aws
  • Loading branch information
stavxyz authored Apr 2, 2018
2 parents e8cd0a6 + da9b11e commit 9f91470
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 39 deletions.
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# tf_mailgun_aws
[![Circle CI](https://circleci.com/gh/samstav/tf_mailgun_aws/tree/master.svg?style=shield)](https://circleci.com/gh/samstav/tf_mailgun_aws)
# terraform-mailgun-aws
[![Circle CI](https://circleci.com/gh/samstav/terraform-mailgun-aws/tree/master.svg?style=shield)](https://circleci.com/gh/samstav/terraform-mailgun-aws)
[![Terraform](https://img.shields.io/badge/terraform-%3E=0.8.0-822ff7.svg)](https://www.terraform.io/)

A Terraform module for creating a Mailgun domain, Route53 Zone, and corresponding DNS records
Expand Down Expand Up @@ -27,7 +27,7 @@ From the [mailgun docs](https://documentation.mailgun.com/quickstart-receiving.h

> Do not configure Receiving MX DNS records if you already have another provider handling inbound mail delivery for your domain (e.g. Gmail). Instead we recommend using a subdomain on Mailgun (e.g. mg.yourdomain.com)
To disable the creation of the MX records, set [the terraform variable `mailgun_set_mx_for_inbound`](https://github.com/samstav/tf_mailgun_aws/blob/6c58d8bc8699866337816f3f583c97bb40105423/variables.tf#L20-L23) to `false`.
To disable the creation of the MX records, set [the terraform variable `mailgun_set_mx_for_inbound`](https://github.com/samstav/terraform-mailgun-aws/blob/6c58d8bc8699866337816f3f583c97bb40105423/variables.tf#L20-L23) to `false`.

## Prerequisites

Expand All @@ -38,30 +38,17 @@ You'll need your Mailgun API Key, found in your control panel homepage.
Sign up: https://mailgun.com/signup
Control Panel: https://mailgun.com/cp

_Mailgun domains do not support `terraform import`, so *you need to let this module
create the mailgun domain for you*, otherwise you end up manually editing your
state file which probably won't end well._


### terraform

https://www.terraform.io/downloads.html

or mac users can `brew install terraform`

The included script can help you configure your [terraform remote state](https://www.terraform.io/docs/state/remote/).

```
$ ./main.py tf-remote-config big-foo.com --dry-run
Would run command:
terraform remote config -state="terraform.tfstate" -backend="S3" \
-backend-config="bucket=terraform-state-big-foo-dot-com" \
-backend-config="key=terraform.tfstate" \
-backend-config="region=us-east-1" -backend-config="encrypt=1"
```

Run the same, but without `--dry-run`, to configure terraform to use remote state. This will also create [your s3 bucket](https://www.terraform.io/docs/state/remote/s3.html) if it doesn't already exist.

Mailgun domains do not support `terraform import`, so you need to let this module
create the mailgun domain for you, otherwise you end up manually editing your
state file which probably won't end well.

## Usage

Utilize this module in one or more of your tf files:
Expand Down Expand Up @@ -92,23 +79,24 @@ variable "mailgun_api_key" {}
variable "mailgun_smtp_password" {}
module "mailer" {
source = "github.com/samstav/tf_mailgun_aws"
source = "github.com/samstav/terraform-mailgun-aws"
domain = "${var.domain}"
mailgun_smtp_password = "${var.mailgun_smtp_password}"
}
```

__*Before running your plan, [fetch the module with `terraform get`](https://www.terraform.io/docs/commands/get.html)*__
__*Before running your plan, [fetch the module with `terraform get -update`](https://www.terraform.io/docs/commands/get.html)*__


Once your definition(s) are complete:

```bash
# This downloads and installs modules needed for your configuration.
# See `terraform get --help` for more info
$ terraform get -update=true
$ terraform get -update
# This generates an execution plan for terraform. To save this to a file you need to supply -out.
# To generate a plan *only* for this module, use -target=module.mailer
# See `terraform plan --help` for more info.
$ terraform plan -out=mailer.plan
# This builds or changes infrastructure according to the terraform execution plan.
Expand All @@ -119,16 +107,16 @@ $ terraform apply mailer.plan
To [pin your configuration to a specific version of this module, use the `?ref` param](https://www.terraform.io/docs/modules/sources.html#ref) and change your `source` line to something like this:

```hcl
source = "github.com/samstav/tf_mailgun_aws?ref=v1.1.0"
source = "github.com/samstav/terraform-mailgun-aws?ref=v1.1.0"
```

See [releases](https://github.com/samstav/tf_mailgun_aws/releases).
See [releases](https://github.com/samstav/terraform-mailgun-aws/releases).


### When using an _existing_ Route53 Zone

To use an existing zone, instead of letting this tf module create the zone,
you need to import your [zone](https://www.terraform.io/docs/providers/aws/r/route53_zone.html) (by id) *into the `tf_mailgun_aws` module* [using `terraform import`](https://www.terraform.io/docs/import/):
you need to import your [zone](https://www.terraform.io/docs/providers/aws/r/route53_zone.html) (by id) *into the `terraform-mailgun-aws` module* [using `terraform import`](https://www.terraform.io/docs/import/):

```bash
$ terraform import module.my_instance.aws_route53_zone.this <your_route53_zone_id>
Expand All @@ -138,7 +126,7 @@ where the `my_instance` portion of this resource is the name you chose:

```hcl
module "my_instance" {
source = "github.com/samstav/tf_mailgun_aws"
source = "github.com/samstav/terraform-mailgun-aws"
}
```

Expand All @@ -150,7 +138,7 @@ $ aws route53 list-hosted-zones-by-name --dns-name big-foo.com

### To refer to the Route53 zone created/used by the module

[This module outputs](https://github.com/samstav/tf_mailgun_aws/blob/master/outputs.tf) the Route53 Zone ID, as well as the NS record values (the nameservers):
[This module outputs](https://github.com/samstav/terraform-mailgun-aws/blob/master/outputs.tf) the Route53 Zone ID, as well as the NS record values (the nameservers):

To refer to these outputs, use `"${module.my_instance.zone_id}"` or `"${module.my_instance.name_servers}"`

Expand All @@ -172,7 +160,7 @@ resource "aws_route53_record" "root" {

### Adding a route in mailgun to forward all mail

Route resources are not available in the [mailgun terraform provider](https://www.terraform.io/docs/providers/mailgun/), so we do it with the script.
Route resources are not available in the [mailgun terraform provider](https://www.terraform.io/docs/providers/mailgun/), so we do it with [the included script](https://github.com/samstav/terraform-mailgun-aws/blob/master/main.py).

```
$ ./main.py create-route big-foo.com --forward bigfoo@gmail.com
Expand Down
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test:
override:
- terraform validate
- terraform get -update=true:
pwd: example
pwd: examples/basic-example
- terraform plan -out=example.plan:
pwd: example
pwd: examples/basic-example
- terraform show example.plan:
pwd: example
pwd: examples/basic-example
2 changes: 1 addition & 1 deletion example/main.tf → examples/basic-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ variable "mailgun_api_key" {}
variable "mailgun_smtp_password" {}

module "mailer" {
source = "../"
source = "../../"
domain = "${var.domain}"
mailgun_smtp_password = "${var.mailgun_smtp_password}"
}
File renamed without changes.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _mailgun_args(_parser):
_parser.add_argument(
'--mailgun-user', '-u',
help='Defaults to the MAILGUN_USER environment variable.',
default=os.getenv('MAILGUN_USER') or None,
default=os.getenv('MAILGUN_USER') or 'api'
)

subparsers = parser.add_subparsers()
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Module: tf_mailgun_aws
* Module: terraform-mailgun-aws
*
* This template creates the following resources
* - A Mailgun domain
Expand All @@ -16,7 +16,7 @@
* where the 'my_instance' portion is the name you choose:
*
* module "my_instance" {
* source = "github.com/samstav/tf_mailgun_aws"
* source = "github.com/samstav/terraform-mailgun-aws"
* }
*
*/
Expand Down Expand Up @@ -50,7 +50,7 @@ resource "mailgun_domain" "this" {
resource "aws_route53_zone" "this" {
# This hack deals with https://github.com/hashicorp/terraform/issues/8511
name = "${element( split("","${var.domain}"), "${ length("${var.domain}") -1 }") == "." ? var.domain : "${var.domain}."}"
comment = "Zone managed by terraform with mailgun mail and created by github.com/samstav/tf_mailgun_aws"
comment = "Zone managed by terraform with mailgun mail and created by github.com/samstav/terraform-mailgun-aws"
force_destroy = false
}

Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ variable "mailgun_wildcard" {

variable "mailgun_set_mx_for_inbound" {
default = 1
description = "Affects tf_mailgun_aws module behavior. Set to false or 0 to prevent this module from setting mailgun.org MX records on your Route53 Hosted Zone. See more information about how terraform handles booleans here: https://www.terraform.io/docs/configuration/variables.html"
description = "Affects terraform-mailgun-aws module behavior. Set to false or 0 to prevent this module from setting mailgun.org MX records on your Route53 Hosted Zone. See more information about how terraform handles booleans here: https://www.terraform.io/docs/configuration/variables.html"
}

variable "record_ttl" {
Expand Down

0 comments on commit 9f91470

Please sign in to comment.