Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created April 2, 2016 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save blakesmith/03fc2048b73a1f47e3c40a9cac1b3d8d to your computer and use it in GitHub Desktop.
Save blakesmith/03fc2048b73a1f47e3c40a9cac1b3d8d to your computer and use it in GitHub Desktop.
Terraform setup for running blakesmith.me
provider "aws" {
alias = "prod"
region = "us-east-1"
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
}
resource "aws_s3_bucket" "origin_blakesmith_me" {
provider = "aws.prod"
bucket = "origin.blakesmith.me"
acl = "public-read"
policy = <<POLICY
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadForGetBucketObjects",
"Effect":"Allow",
"Principal": "*",
"Action":"s3:GetObject",
"Resource":["arn:aws:s3:::origin.blakesmith.me/*"
]
}
]
}
POLICY
website {
index_document = "index.html"
}
}
resource "aws_route53_zone" "blakesmith_me" {
provider = "aws.prod"
name = "blakesmith.me"
}
resource "aws_route53_record" "origin" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "origin.blakesmith.me"
type = "A"
alias {
name = "${aws_s3_bucket.origin_blakesmith_me.website_domain}"
zone_id = "${aws_s3_bucket.origin_blakesmith_me.hosted_zone_id}"
evaluate_target_health = false
}
}
resource "aws_route53_record" "root" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "blakesmith.me"
type = "A"
alias {
name = "${aws_cloudfront_distribution.blakesmith_distribution.domain_name}"
zone_id = "Z2FDTNDATAQYW2"
evaluate_target_health = false
}
}
resource "aws_route53_record" "www" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "www.blakesmith.me"
type = "A"
alias {
name = "${aws_cloudfront_distribution.blakesmith_distribution.domain_name}"
zone_id = "Z2FDTNDATAQYW2"
evaluate_target_health = false
}
}
resource "aws_route53_record" "ssh" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "ssh.blakesmith.me"
type = "A"
ttl = "300"
records = ["162.243.108.149"]
}
resource "aws_route53_record" "metra" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "metra.blakesmith.me"
type = "A"
ttl = "300"
records = ["162.243.108.149"]
}
resource "aws_route53_record" "skeeter" {
provider = "aws.prod"
zone_id = "${aws_route53_zone.blakesmith_me.zone_id}"
name = "skeeter.blakesmith.me"
type = "A"
ttl = "300"
records = ["162.243.108.149"]
}
resource "aws_cloudfront_distribution" "blakesmith_distribution" {
provider = "aws.prod"
origin {
domain_name = "origin.blakesmith.me.s3.amazonaws.com"
origin_id = "blakesmith_origin"
s3_origin_config {
}
}
enabled = true
default_root_object = "index.html"
aliases = ["blakesmith.me", "www.blakesmith.me"]
price_class = "PriceClass_200"
retain_on_delete = true
default_cache_behavior {
allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
cached_methods = [ "GET", "HEAD" ]
target_origin_id = "blakesmith_origin"
forwarded_values {
query_string = true
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
default_cache_behavior {
allowed_methods = [ "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT" ]
cached_methods = [ "GET", "HEAD" ]
target_origin_id = "blakesmith_origin"
forwarded_values {
query_string = true
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
viewer_certificate {
cloudfront_default_certificate = true
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment