From 12560cbd6c20b8a4e64b2f3f819b154f9848b892 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Sun, 1 Apr 2018 12:13:24 -0500 Subject: [PATCH 1/5] mailgun basic auth just uses 'api' user now --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index beb96a0..a2a74d3 100755 --- a/main.py +++ b/main.py @@ -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() From f95cb88b9a4e6eac40ae42502bde37f29b2b41a7 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Mon, 2 Apr 2018 13:07:43 -0500 Subject: [PATCH 2/5] rename to terraform-mailgun-aws --- README.md | 18 +++++++++--------- main.tf | 6 +++--- variables.tf | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e309b83..11875e7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -92,7 +92,7 @@ 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}" } @@ -119,16 +119,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 @@ -138,7 +138,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" } ``` @@ -150,7 +150,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}"` diff --git a/main.tf b/main.tf index 1a38786..c7c91bc 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ /* - * Module: tf_mailgun_aws + * Module: terraform-mailgun-aws * * This template creates the following resources * - A Mailgun domain @@ -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" * } * */ @@ -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 } diff --git a/variables.tf b/variables.tf index 58057d3..ef68e66 100644 --- a/variables.tf +++ b/variables.tf @@ -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" { From 8f28855c0bba651909110bdbfdf3f999277fb974 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Mon, 2 Apr 2018 13:13:53 -0500 Subject: [PATCH 3/5] reorganize example(s) according to tf registry docs --- circle.yml | 6 +++--- {example => examples/basic-example}/main.tf | 0 {example => examples/basic-example}/terraform.tfvars | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename {example => examples/basic-example}/main.tf (100%) rename {example => examples/basic-example}/terraform.tfvars (100%) diff --git a/circle.yml b/circle.yml index c0271cd..181f43e 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/example/main.tf b/examples/basic-example/main.tf similarity index 100% rename from example/main.tf rename to examples/basic-example/main.tf diff --git a/example/terraform.tfvars b/examples/basic-example/terraform.tfvars similarity index 100% rename from example/terraform.tfvars rename to examples/basic-example/terraform.tfvars From 850f9cf13eace9b5c502e3407e2e9cdb5a077c99 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Mon, 2 Apr 2018 16:45:01 -0500 Subject: [PATCH 4/5] update relative path to root module --- examples/basic-example/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic-example/main.tf b/examples/basic-example/main.tf index 0b1c557..9b9babb 100644 --- a/examples/basic-example/main.tf +++ b/examples/basic-example/main.tf @@ -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}" } From da9b11ee1dbaf3b4222588d0649f8852d1340806 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Mon, 2 Apr 2018 16:53:41 -0500 Subject: [PATCH 5/5] remote deprecated 'remote state' docs --- README.md | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 11875e7..3ae0c9e 100644 --- a/README.md +++ b/README.md @@ -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: @@ -99,7 +86,7 @@ module "mailer" { ``` -__*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: @@ -107,8 +94,9 @@ 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. @@ -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