Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #275 from dividehex/terraform
Browse files Browse the repository at this point in the history
Terraform
  • Loading branch information
dividehex committed Mar 20, 2017
2 parents f786bd3 + 753a2aa commit fc0f95b
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -62,3 +62,6 @@ docs/_build/
# Dev env
logs/*.log
slaves.json

# Terraform state files
.terraform
1 change: 1 addition & 0 deletions terraform/base/init.sh
1 change: 1 addition & 0 deletions terraform/base/initialize.tf
4 changes: 4 additions & 0 deletions terraform/base/provider.tf
@@ -0,0 +1,4 @@
provider "aws" {
region = "${var.region}"
profile = "${var.profile}"
}
1 change: 1 addition & 0 deletions terraform/base/resources.tf
94 changes: 94 additions & 0 deletions terraform/base/route53.tf
@@ -0,0 +1,94 @@
# Route 53 resources

# Hosted Zone for mozilla-releng.net
resource "aws_route53_zone" "mozilla-releng" {
name = "mozilla-releng.net."
}

# A list of CNAMEs for heroku apps
variable "heroku_cnames" {
default = ["archiver",
"archiver.staging",
"clobberer",
"clobberer.staging",
"dashboard.shipit",
"dashboard.shipit.staging",
"mapper",
"mapper.staging",
"tooltool",
"tooltool.staging",
"treestatus",
"treestatus.staging"]
}

# CNAME records for heroku apps
resource "aws_route53_record" "heroku-cname" {
zone_id = "${aws_route53_zone.mozilla-releng.zone_id}"
name = "${element(var.heroku_cnames, count.index)}.mozilla-releng.net"
type = "CNAME"
ttl = "180"
count = "${length(var.heroku_cnames)}"
records = ["${element(var.heroku_cnames, count.index)}.mozilla-releng.net.herokudns.com"]
}

# Coalesce app cname is unique because it uses the old ssl endpoint
resource "aws_route53_record" "heroku-coalease-cname" {
zone_id = "${aws_route53_zone.mozilla-releng.zone_id}"
name = "coalesce.mozilla-releng.net"
type = "CNAME"
ttl = "180"
records = ["oita-54541.herokussl.com"]
}

# Cloudfront Alias names
variable "cloudfront_alias" {
default = ["docs",
"docs.staging",
"shipit",
"shiptit.staging",
"www",
"staging"]
}

# Cloudfront Alias Targets
# In the future, these may be sourced directly from terraform cloudfront resources
# should we decide to manage cloudfronts in terraform
variable "cloudfront_alias_domain" {
type = "map"
default = {
docs = "d1945er7u4liht"
docs.staging = "d32jt14rospqzr"
shipit = "dve8yd1431ifz"
shiptit.staging = "d2ld4e8bl8yd1l"
www = "d1qqwps52z1e12"
staging = "dpwmwa9tge2p3"
}
}

# A (Alias) records for cloudfront apps
resource "aws_route53_record" "cloudfront-alias" {
zone_id = "${aws_route53_zone.mozilla-releng.zone_id}"
name = "${element(var.cloudfront_alias, count.index)}.mozilla-releng.net"
type = "A"
count = "${length(var.cloudfront_alias)}"

alias {
name = "${var.cloudfront_alias_domain[element(var.cloudfront_alias, count.index)]}.cloudfront.net."
zone_id = "Z2FDTNDATAQYW2"
evaluate_target_health = false
}
}

# A special root alias that points to www.mozilla-releng.net
resource "aws_route53_record" "root-alias" {
zone_id = "${aws_route53_zone.mozilla-releng.zone_id}"
name = "mozilla-releng.net"
type = "A"

alias {
name = "www.mozilla-releng.net"
zone_id = "${aws_route53_zone.mozilla-releng.zone_id}"
evaluate_target_health = false
}
}

7 changes: 7 additions & 0 deletions terraform/base/s3.tf
@@ -0,0 +1,7 @@
resource "aws_s3_bucket" "base_bucket" {
bucket = "${var.base_bucket}"
acl = "private"
versioning {
enabled = true
}
}
3 changes: 3 additions & 0 deletions terraform/base/terraform.tfvars
@@ -0,0 +1,3 @@
profile="mozilla-releng"
env="base"
region="us-east-1"
1 change: 1 addition & 0 deletions terraform/base/variables.tf
14 changes: 14 additions & 0 deletions terraform/init.sh
@@ -0,0 +1,14 @@
#!/bin/bash
#
set -euf -o pipefail

tfenv=$(basename $(pwd))

# Set up remote state
terraform remote config -backend=s3 \
-backend-config="bucket=tf-base" \
-backend-config="key=tf_state/${tfenv}/terraform.tfstate" \
-backend-config="region=us-east-1"

# Update modules
terraform get
14 changes: 14 additions & 0 deletions terraform/initialize.tf
@@ -0,0 +1,14 @@
# This file contains empty declarations for variables that will be definied in each
# environments terraform.tfvars file

variable "profile" {
description = "Name of the AWS profile to grab credentials from"
}

variable "region" {
description = "The AWS region to create things in."
}

variable "env" {
description = "Environment name"
}
14 changes: 14 additions & 0 deletions terraform/resources.tf
@@ -0,0 +1,14 @@
# This file contains shared global resources

# Configure remote state
# Outputs can be accessed via ${data.terraform_remote_state.base.output_name}
data "terraform_remote_state" "base" {
backend = "s3"
config {
encrypt = true
acl = "private"
bucket = "${var.base_bucket}"
region = "us-east-1"
key = "tf_state/base/terraform.tfstate"
}
}
6 changes: 6 additions & 0 deletions terraform/variables.tf
@@ -0,0 +1,6 @@
# Global variables

variable "base_bucket" {
description = "S3 bucket for storing terraform state, ssh pub keys, etc"
default = "tf-base"
}

0 comments on commit fc0f95b

Please sign in to comment.