This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
region = "us-east-1" | |
aws_access_key = "..." | |
aws_secret_key = "..." | |
# your domain | |
# assumes you have a hosted zone of the same name | |
# in route 53 | |
# this is also the name of the domain that will be | |
# created in mailgun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the dev environment's input variables | |
variable "region" { } | |
variable "aws_access_key" { } | |
variable "aws_secret_key" { } | |
variable "domain" { } | |
variable "github_username" { } | |
variable "mailgun_api_key" { } | |
variable "mailgun_smtp_password" { } | |
# set up the aws provider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_s3_bucket" "b" { | |
bucket = "my_tf_test_bucket" | |
acl = "private" | |
tags { | |
Name = "My bucket" | |
Environment = "Dev" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_route53_record" "mailgun_sending_1" { | |
zone_id = "${data.aws_route53_zone.domain.zone_id}" | |
ttl = "300" | |
name = "${mailgun_domain.domain.sending_records.0.name}" | |
type = "${mailgun_domain.domain.sending_records.0.record_type}" | |
records = ["${mailgun_domain.domain.sending_records.0.value}"] | |
} | |
resource "aws_route53_record" "mailgun_sending_2" { | |
zone_id = "${data.aws_route53_zone.domain.zone_id}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fetches and the existing hosted zone for the domain | |
data "aws_route53_zone" "domain" { | |
name = "${var.domain}." | |
} | |
# apex domain dns entry | |
resource "aws_route53_record" "apex" { | |
zone_id = "${data.aws_route53_zone.domain.zone_id}" | |
name = "${data.aws_route53_zone.domain.name}" | |
type = "A" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ideally we could create the dns entries by iterating over | |
# each record but terraform currently doesn't computed variables | |
# when using count. | |
resource "aws_route53_record" "mailgun_sending" { | |
# create an route 53 entry for each record for the mailgun domain | |
count = "${length(mailgun_domain.domain.sending_records)}" | |
zone_id = "${data.aws_route53_zone.domain.zone_id}" | |
ttl = "300" | |
# select the record name from the current count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "mailgun_domain" "domain" { | |
name = "${var.domain}" | |
spam_action = "disabled" | |
smtp_password = "${var.mailgun_smtp_password}" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the cloudfront distribution | |
resource "aws_cloudfront_distribution" "s3_distribution" { | |
origin { | |
domain_name = "${aws_s3_bucket.website.bucket_domain_name}" | |
origin_id = "websiteS3Origin" | |
} | |
aliases = ["${var.domain}", "www.${var.domain}"] | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the schedule | |
resource "aws_cloudwatch_event_rule" "generate_website_event" { | |
name = "generate_website_event" | |
description = "Fires every 15 minutes" | |
schedule_expression = "rate(15 minutes)" | |
} | |
# the event target | |
resource "aws_cloudwatch_event_target" "generate_website_event_target" { | |
rule = "${aws_cloudwatch_event_rule.generate_website_event.name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the s3 bucket | |
resource "aws_s3_bucket" "website" { | |
bucket = "${var.domain}" | |
# set to public if you're not using a CDN | |
acl = "private" | |
policy = "${data.aws_iam_policy_document.website_bucket_policy.json}" | |
website { | |
index_document = "index.html" | |
} |