Skip to content

Instantly share code, notes, and snippets.

@jschr
jschr / dev.tfvars
Last active April 12, 2017 13:22
terraform vars
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
@jschr
jschr / dev.tf
Last active April 12, 2017 23:16
terraform dev environment
# 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
@jschr
jschr / s3_bucket.tf
Created April 12, 2017 03:59
terraform sample
resource "aws_s3_bucket" "b" {
bucket = "my_tf_test_bucket"
acl = "private"
tags {
Name = "My bucket"
Environment = "Dev"
}
}
@jschr
jschr / mailgun.tf
Created April 12, 2017 02:56
mailgun dns records
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}"
@jschr
jschr / route53.tf
Last active April 12, 2017 02:39
route 53
# 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"
@jschr
jschr / mailgun-broken.tf
Last active April 13, 2017 01:13
terraform dns entries broken
# 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
@jschr
jschr / mailgun.tf
Created April 12, 2017 02:25
terraform mailgun provider
resource "mailgun_domain" "domain" {
name = "${var.domain}"
spam_action = "disabled"
smtp_password = "${var.mailgun_smtp_password}"
}
@jschr
jschr / cloudfront.tf
Last active April 12, 2017 02:24
terraform cloudfront
# 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}"]
...
@jschr
jschr / cloudwatch.tf
Last active April 12, 2017 02:23
terraform cloudwatch
# 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}"
@jschr
jschr / s3.tf
Last active April 12, 2017 04:25
terraform s3
# 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"
}