Skip to content
This repository was archived by the owner on Jun 26, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions terraform/modules/aws/compute/haproxy/haproxy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ resource "aws_security_group" "haproxy" {
vpc_id = "${var.vpc_id}"
description = "HAProxy security group"

tags {
Name = "${var.name}"
tags {
Name = "${var.name}"
Demo = "true"
}
lifecycle { create_before_destroy = true }
Expand Down Expand Up @@ -56,12 +56,10 @@ resource "aws_security_group" "haproxy" {
}
}

resource "template_file" "user_data" {
template = "${path.module}/haproxy.sh.tpl"
data "template_file" "user_data" {
template = "${file("${path.module}/haproxy.sh.tpl")}"
count = "${var.nodes}"

lifecycle { create_before_destroy = true }

vars {
atlas_username = "${var.atlas_username}"
atlas_environment = "${var.atlas_environment}"
Expand All @@ -76,7 +74,7 @@ resource "aws_instance" "haproxy" {
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${element(split(",", var.subnet_ids), count.index)}"
user_data = "${element(template_file.user_data.*.rendered, count.index)}"
user_data = "${element(data.template_file.user_data.*.rendered, count.index)}"

vpc_security_group_ids = ["${aws_security_group.haproxy.id}"]

Expand Down
37 changes: 19 additions & 18 deletions terraform/modules/aws/compute/nodejs/nodejs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,17 @@ resource "aws_elb" "green" {
}
}

resource "terraform_remote_state" "aws_global" {
data "terraform_remote_state" "aws_global" {
backend = "atlas"

config {
name = "${var.atlas_username}/${var.atlas_aws_global}"
}

lifecycle { create_before_destroy = true }
}

resource "template_file" "blue_user_data" {
template = "${path.module}/nodejs.sh.tpl"

lifecycle { create_before_destroy = true }
data "template_file" "blue_user_data" {
template = "${file("${path.module}/nodejs.sh.tpl")}"

vars {
atlas_username = "${var.atlas_username}"
Expand All @@ -171,15 +168,13 @@ resource "template_file" "blue_user_data" {
vault_token = "${var.vault_token}"
vault_policy = "${var.vault_policy}"
aws_region = "${var.region}"
aws_access_id = "${element(split(",", terraform_remote_state.aws_global.output.iam_vault_access_ids), index(split(",", terraform_remote_state.aws_global.output.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_secret_key = "${element(split(",", terraform_remote_state.aws_global.output.iam_vault_secret_keys), index(split(",", terraform_remote_state.aws_global.output.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_access_id = "${element(split(",", data.terraform_remote_state.aws_global.iam_vault_access_ids), index(split(",", data.terraform_remote_state.aws_global.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_secret_key = "${element(split(",", data.terraform_remote_state.aws_global.iam_vault_secret_keys), index(split(",", data.terraform_remote_state.aws_global.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
}
}

resource "template_file" "green_user_data" {
template = "${path.module}/nodejs.sh.tpl"

lifecycle { create_before_destroy = true }
data "template_file" "green_user_data" {
template = "${file("${path.module}/nodejs.sh.tpl")}"

vars {
atlas_username = "${var.atlas_username}"
Expand All @@ -192,8 +187,8 @@ resource "template_file" "green_user_data" {
vault_token = "${var.vault_token}"
vault_policy = "${var.vault_policy}"
aws_region = "${var.region}"
aws_access_id = "${element(split(",", terraform_remote_state.aws_global.output.iam_vault_access_ids), index(split(",", terraform_remote_state.aws_global.output.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_secret_key = "${element(split(",", terraform_remote_state.aws_global.output.iam_vault_secret_keys), index(split(",", terraform_remote_state.aws_global.output.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_access_id = "${element(split(",", data.terraform_remote_state.aws_global.iam_vault_access_ids), index(split(",", data.terraform_remote_state.aws_global.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
aws_secret_key = "${element(split(",", data.terraform_remote_state.aws_global.iam_vault_secret_keys), index(split(",", data.terraform_remote_state.aws_global.iam_vault_users), format("vault-%s", var.atlas_environment)))}"
}
}

Expand All @@ -210,21 +205,24 @@ module "deploy" {
blue_ami = "${var.blue_ami}"
blue_nodes = "${var.blue_nodes}"
blue_instance_type = "${var.blue_instance_type}"
blue_user_data = "${template_file.blue_user_data.rendered}"
blue_user_data = "${data.template_file.blue_user_data.rendered}"
green_elb_id = "${aws_elb.green.id}"
green_ami = "${var.green_ami}"
green_nodes = "${var.green_nodes}"
green_instance_type = "${var.green_instance_type}"
green_user_data = "${template_file.green_user_data.rendered}"
green_user_data = "${data.template_file.green_user_data.rendered}"
}

resource "aws_route53_record" "blue" {
zone_id = "${var.route_zone_id}"
name = "nodejs.${var.sub_domain}"
type = "A"
weight = "${var.blue_weight}"
set_identifier = "blue"

weighted_routing_policy {
weight = "${var.blue_weight}"
}

alias {
name = "${aws_elb.blue.dns_name}"
zone_id = "${aws_elb.blue.zone_id}"
Expand All @@ -236,9 +234,12 @@ resource "aws_route53_record" "green" {
zone_id = "${var.route_zone_id}"
name = "nodejs.${var.sub_domain}"
type = "A"
weight = "${var.green_weight}"
set_identifier = "green"

weighted_routing_policy {
weight = "${var.green_weight}"
}

alias {
name = "${aws_elb.green.dns_name}"
zone_id = "${aws_elb.green.zone_id}"
Expand Down
8 changes: 3 additions & 5 deletions terraform/modules/aws/data/consul/consul.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ resource "aws_security_group" "consul" {
}
}

resource "template_file" "user_data" {
data "template_file" "user_data" {
count = "${var.nodes}"
template = "${path.module}/consul.sh.tpl"

lifecycle { create_before_destroy = true }
template = "${file("${path.module}/consul.sh.tpl")}"

vars {
atlas_username = "${var.atlas_username}"
Expand All @@ -63,7 +61,7 @@ resource "aws_instance" "consul" {
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${element(split(",", var.private_subnet_ids), count.index)}"
user_data = "${element(template_file.user_data.*.rendered, count.index)}"
user_data = "${element(data.template_file.user_data.*.rendered, count.index)}"

vpc_security_group_ids = ["${aws_security_group.consul.id}"]

Expand Down
8 changes: 3 additions & 5 deletions terraform/modules/aws/data/vault/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ resource "aws_security_group" "vault" {
}
}

resource "template_file" "user_data" {
data "template_file" "user_data" {
count = "${var.nodes}"
template = "${path.module}/vault.sh.tpl"

lifecycle { create_before_destroy = true }
template = "${file("${path.module}/vault.sh.tpl")}"

vars {
atlas_username = "${var.atlas_username}"
Expand All @@ -65,7 +63,7 @@ resource "aws_instance" "vault" {
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
subnet_id = "${element(split(",", var.private_subnet_ids), count.index)}"
user_data = "${element(template_file.user_data.*.rendered, count.index)}"
user_data = "${element(data.template_file.user_data.*.rendered, count.index)}"

vpc_security_group_ids = ["${aws_security_group.vault.id}"]

Expand Down
5 changes: 2 additions & 3 deletions terraform/modules/aws/util/artifact/artifact.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ variable "atlas_username" { }
variable "artifact_name" { }
variable "artifact_version" { default = "latest" }

resource "atlas_artifact" "artifact" {
data "atlas_artifact" "artifact" {
name = "${var.atlas_username}/${var.artifact_name}"
type = "${var.type}"
count = "${length(split(",", var.artifact_version))}"
version = "${element(split(",", var.artifact_version), count.index)}"

lifecycle { create_before_destroy = true }
metadata { region = "${var.region}" }
}

output "amis" { value = "${join(",", atlas_artifact.artifact.*.metadata_full.ami_id)}" }
output "amis" { value = "${join(",", data.atlas_artifact.artifact.*.metadata_full.ami_id)}" }
22 changes: 10 additions & 12 deletions terraform/providers/aws/us_east_1_prod/us_east_1_prod.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ resource "aws_key_pair" "site_key" {
lifecycle { create_before_destroy = true }
}

resource "terraform_remote_state" "aws_global" {
data "terraform_remote_state" "aws_global" {
backend = "atlas"

config {
name = "${var.atlas_username}/${var.atlas_aws_global}"
}

lifecycle { create_before_destroy = true }
}

module "network" {
Expand All @@ -91,7 +89,7 @@ module "network" {
key_name = "${aws_key_pair.site_key.key_name}"
private_key = "${var.site_private_key}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"

bastion_instance_type = "${var.bastion_instance_type}"
openvpn_instance_type = "${var.openvpn_instance_type}"
Expand Down Expand Up @@ -138,7 +136,7 @@ module "data" {
atlas_environment = "${var.atlas_environment}"
atlas_token = "${var.atlas_token}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"

consul_amis = "${module.artifact_consul.amis}"
consul_node_count = "${var.consul_node_count}"
Expand Down Expand Up @@ -193,7 +191,7 @@ module "compute" {
atlas_aws_global = "${var.atlas_aws_global}"
atlas_token = "${var.atlas_token}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"
vault_token = "${var.vault_token}"

haproxy_amis = "${module.artifact_haproxy.amis}"
Expand All @@ -213,20 +211,20 @@ module "compute" {
module "website" {
source = "../../../modules/aws/util/website"

fqdn = "${var.sub_domain}.${terraform_remote_state.aws_global.output.prod_fqdn}"
fqdn = "${var.sub_domain}.${data.terraform_remote_state.aws_global.prod_fqdn}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"
}

output "configuration" {
value = <<CONFIGURATION

Visit the static website hosted on S3:
Prod: ${terraform_remote_state.aws_global.output.prod_fqdn}
${terraform_remote_state.aws_global.output.prod_endpoint}
Prod: ${data.terraform_remote_state.aws_global.prod_fqdn}
${data.terraform_remote_state.aws_global.prod_endpoint}

Staging: ${terraform_remote_state.aws_global.output.staging_fqdn}
${terraform_remote_state.aws_global.output.staging_endpoint}
Staging: ${data.terraform_remote_state.aws_global.staging_fqdn}
${data.terraform_remote_state.aws_global.staging_endpoint}

Region: ${module.website.fqdn}
${module.website.endpoint}
Expand Down
22 changes: 10 additions & 12 deletions terraform/providers/aws/us_east_1_staging/us_east_1_staging.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ resource "aws_key_pair" "site_key" {
lifecycle { create_before_destroy = true }
}

resource "terraform_remote_state" "aws_global" {
data "terraform_remote_state" "aws_global" {
backend = "atlas"

config {
name = "${var.atlas_username}/${var.atlas_aws_global}"
}

lifecycle { create_before_destroy = true }
}

module "network" {
Expand All @@ -91,7 +89,7 @@ module "network" {
key_name = "${aws_key_pair.site_key.key_name}"
private_key = "${var.site_private_key}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"

bastion_instance_type = "${var.bastion_instance_type}"
openvpn_instance_type = "${var.openvpn_instance_type}"
Expand Down Expand Up @@ -138,7 +136,7 @@ module "data" {
atlas_environment = "${var.atlas_environment}"
atlas_token = "${var.atlas_token}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"

consul_amis = "${module.artifact_consul.amis}"
consul_node_count = "${var.consul_node_count}"
Expand Down Expand Up @@ -193,7 +191,7 @@ module "compute" {
atlas_aws_global = "${var.atlas_aws_global}"
atlas_token = "${var.atlas_token}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"
vault_token = "${var.vault_token}"

haproxy_amis = "${module.artifact_haproxy.amis}"
Expand All @@ -213,20 +211,20 @@ module "compute" {
module "website" {
source = "../../../modules/aws/util/website"

fqdn = "${var.sub_domain}.${terraform_remote_state.aws_global.output.prod_fqdn}"
fqdn = "${var.sub_domain}.${data.terraform_remote_state.aws_global.prod_fqdn}"
sub_domain = "${var.sub_domain}"
route_zone_id = "${terraform_remote_state.aws_global.output.zone_id}"
route_zone_id = "${data.terraform_remote_state.aws_global.zone_id}"
}

output "configuration" {
value = <<CONFIGURATION

Visit the static website hosted on S3:
Prod: ${terraform_remote_state.aws_global.output.prod_fqdn}
${terraform_remote_state.aws_global.output.prod_endpoint}
Prod: ${data.terraform_remote_state.aws_global.prod_fqdn}
${data.terraform_remote_state.aws_global.prod_endpoint}

Staging: ${terraform_remote_state.aws_global.output.staging_fqdn}
${terraform_remote_state.aws_global.output.staging_endpoint}
Staging: ${data.terraform_remote_state.aws_global.staging_fqdn}
${data.terraform_remote_state.aws_global.staging_endpoint}

Region: ${module.website.fqdn}
${module.website.endpoint}
Expand Down