Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi az and fix aws. #385

Merged
merged 1 commit into from
Jul 14, 2015
Merged
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
2 changes: 1 addition & 1 deletion bootstrap/aws-public/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export TF_VAR_region=${TF_VAR_region:-eu-west-1}
export TF_VAR_master_size=${TF_VAR_master_size:-m1.medium}
export TF_VAR_slave_size=${TF_VAR_slave_size:-m1.medium}
export TF_VAR_slaves=${TF_VAR_slaves:-1}
export TF_VAR_subnet_availability_zone=${TF_VAR_subnet_availability_zone:-eu-west-1a}
export TF_VAR_availability_zones=${TF_VAR_availability_zones:-'eu-west-1a,eu-west-1b,eu-west-1c'}

export APOLLO_consul_dc=${APOLLO_consul_dc:-$TF_VAR_region}
export APOLLO_mesos_cluster_name=${APOLLO_mesos_cluster_name:-$TF_VAR_region}
8 changes: 4 additions & 4 deletions bootstrap/aws/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export ANSIBLE_SSH_ARGS="-F ${APOLLO_ROOT}/terraform/${APOLLO_PROVIDER}/ssh.conf
# so no really needed to export them. Exporting for consitency.
export TF_VAR_atlas_artifact_master=${TF_VAR_atlas_artifact_master:-capgemini/apollo-ubuntu-14.04-amd64}
export TF_VAR_atlas_artifact_slave=${TF_VAR_atlas_artifact_slave:-capgemini/apollo-ubuntu-14.04-amd64}
export TF_VAR_atlas_artifact_version_master=${TF_VAR_atlas_artifact_version_master:-latest}
export TF_VAR_atlas_artifact_version_slave=${TF_VAR_atlas_artifact_version_slave:-latest}
export TF_VAR_atlas_artifact_version_master=${TF_VAR_atlas_artifact_version_master:-6}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does latest no longer work?

export TF_VAR_atlas_artifact_version_slave=${TF_VAR_atlas_artifact_version_slave:-6}

export TF_VAR_region=${TF_VAR_region:-eu-west-1}
export TF_VAR_master_size=${TF_VAR_master_size:-m1.medium}
export TF_VAR_slave_size=${TF_VAR_slave_size:-m1.medium}
export TF_VAR_slaves=${TF_VAR_slaves:-1}
export TF_VAR_subnet_availability_zone=${TF_VAR_subnet_availability_zone:-eu-west-1a}

export TF_VAR_availability_zones=${TF_VAR_availability_zones:-'eu-west-1a,eu-west-1b,eu-west-1c'}
export TF_VAR_public_subnet_availability_zone=${TF_VAR_public_subnet_availability_zone:-'eu-west-1a'}
export APOLLO_consul_dc=${APOLLO_consul_dc:-$TF_VAR_region}
export APOLLO_mesos_cluster_name=${APOLLO_mesos_cluster_name:-$TF_VAR_region}
6 changes: 3 additions & 3 deletions bootstrap/aws/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function set_vpn() {

ansible_ssh_config() {
pushd "${APOLLO_ROOT}/terraform/${APOLLO_PROVIDER}"
export APOLLO_bastion_ip=$(terraform output bastion.ip)
export APOLLO_bastion_ip=$( terraform output bastion.ip )

# Virtual private cloud CIDR IP.
ip=$( terraform output vpc_cidr_block.ip )
Expand All @@ -27,7 +27,7 @@ ansible_ssh_config() {
User ubuntu
HostName $APOLLO_bastion_ip
ProxyCommand none
IdentityFile $TF_VAR_key_file
IdentityFile $TF_VAR_private_key_file
BatchMode yes
PasswordAuthentication no
UserKnownHostsFile /dev/null
Expand All @@ -41,7 +41,7 @@ ansible_ssh_config() {
ControlPath ~/.ssh/mux-%r@%h:%p
ControlPersist 30m
User ubuntu
IdentityFile $TF_VAR_key_file
IdentityFile $TF_VAR_private_key_file
UserKnownHostsFile /dev/null
EOF
popd
Expand Down
Binary file modified docs/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion terraform/aws-public/elb.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "aws_elb" "web" {
name = "apollo-elb"

subnets = ["${aws_subnet.public.id}"]
subnets = ["${aws_subnet.public.*.id}"]

listener {
instance_port = 80
Expand Down
2 changes: 1 addition & 1 deletion terraform/aws-public/mesos-masters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resource "aws_instance" "mesos-master" {
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
count = "${var.masters}"
key_name = "${aws_key_pair.deployer.key_name}"
subnet_id = "${aws_subnet.public.id}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
source_dest_check = false
security_groups = ["${aws_security_group.default.id}"]
tags = {
Expand Down
2 changes: 1 addition & 1 deletion terraform/aws-public/mesos-slaves.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resource "aws_instance" "mesos-slave" {
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
count = "${var.slaves}"
key_name = "${aws_key_pair.deployer.key_name}"
subnet_id = "${aws_subnet.public.id}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
source_dest_check = false
security_groups = ["${aws_security_group.default.id}"]
depends_on = ["aws_instance.mesos-master"]
Expand Down
7 changes: 4 additions & 3 deletions terraform/aws-public/public-subnet.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ resource "aws_internet_gateway" "public" {
/* Public subnet */
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.default.id}"
availability_zone = "${var.subnet_availability_zone}"
cidr_block = "${var.public_subnet_cidr_block}"
count = "${length(split(",", var.availability_zones))}"
availability_zone = "${element(split(",", var.availability_zones), count.index)}"
cidr_block = "10.0.${count.index}.0/24"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.public"]
tags {
Expand All @@ -34,6 +35,6 @@ resource "aws_main_route_table_association" "public" {

/* Associate the routing table to public subnet */
resource "aws_route_table_association" "public" {
subnet_id = "${aws_subnet.public.id}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
route_table_id = "${aws_route_table.public.id}"
}
16 changes: 3 additions & 13 deletions terraform/aws-public/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,14 @@ variable "region" {
default = "eu-west-1"
}

variable "availability_zone" {
description = "Availability zone for Apollo."
default = "eu-west-1b"
}

variable "vpc_cidr_block" {
description = "Cidr block for the VPC."
default = "10.0.0.0/16"
}

variable "subnet_availability_zone" {
description = "Availability zone for Apollo subnet."
default = "eu-west-1b"
}

variable "public_subnet_cidr_block" {
description = "CIDR for public subnet"
default = "10.0.0.0/24"
variable "availability_zones" {
description = "AWS availability zones list separated by ','"
default = ""
}

variable "slaves" {
Expand Down
13 changes: 9 additions & 4 deletions terraform/aws/bastion-server.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
resource "aws_key_pair" "deployer" {
key_name = "${var.key_name}"
public_key = "${file(var.key_file)}"
}

/* NAT/VPN server */
resource "aws_instance" "bastion" {
ami = "${lookup(var.amis, var.region)}"
instance_type = "t2.micro"
subnet_id = "${aws_subnet.public.id}"
security_groups = ["${aws_security_group.default.id}", "${aws_security_group.bastion.id}"]
depends_on = ["aws_internet_gateway.public"]
key_name = "${var.key_name}"
depends_on = ["aws_internet_gateway.public", "aws_key_pair.deployer"]
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
tags = {
Name = "apollo-mesos-bastion"
role = "bastion"
}
connection {
user = "ubuntu"
key_file = "${var.key_file}"
user = "ubuntu"
key_file = "${var.private_key_file}"
}
provisioner "remote-exec" {
inline = [
Expand Down
10 changes: 5 additions & 5 deletions terraform/aws/mesos-masters.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* Base packer build we use for provisioning master instances */
resource "atlas_artifact" "mesos-master" {
name = "${var.atlas_artifact.master}"
type = "aws.ami"
name = "${var.atlas_artifact.master}"
type = "aws.ami"
version = "${var.atlas_artifact_version.master}"
}

/* Mesos master instances */
resource "aws_instance" "mesos-master" {
instance_type = "${var.instance_type.master}"
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
count = "${var.masters}"
key_name = "${var.key_name}"
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
subnet_id = "${aws_subnet.private.id}"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
security_groups = ["${aws_security_group.default.id}"]
depends_on = ["aws_instance.bastion", "aws_internet_gateway.public"]
private_ip = "${lookup(var.master_ips, concat("master-", count.index))}"
tags = {
Name = "apollo-mesos-master-${count.index}"
role = "mesos_masters"
Expand Down
13 changes: 7 additions & 6 deletions terraform/aws/mesos-slaves.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* Base packer build we use for provisioning slave instances */
resource "atlas_artifact" "mesos-slave" {
name = "${var.atlas_artifact.slave}"
type = "aws.ami"
name = "${var.atlas_artifact.slave}"
type = "aws.ami"
version = "${var.atlas_artifact_version.slave}"
}

/* Mesos slave instances */
resource "aws_instance" "mesos-slave" {
instance_type = "${var.instance_type.slave}"
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
ami = "${replace(atlas_artifact.mesos-slave.id, concat(var.region, ":"), "")}"
count = "${var.slaves}"
key_name = "${var.key_name}"
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
subnet_id = "${aws_subnet.private.id}"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
security_groups = ["${aws_security_group.default.id}"]
depends_on = ["aws_instance.bastion", "aws_internet_gateway.public", "aws_instance.mesos-master"]
tags = {
Expand All @@ -28,7 +29,7 @@ resource "aws_instance" "mesos-slave" {
/* Load balancer */
resource "aws_elb" "app" {
name = "apollo-mesos-elb"
subnets = ["${aws_subnet.public.id}"]
subnets = ["${aws_subnet.public.*.id}"]
security_groups = ["${aws_security_group.default.id}", "${aws_security_group.web.id}"]

listener {
Expand Down
8 changes: 5 additions & 3 deletions terraform/aws/private-subnet.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* Private subnet */
resource "aws_subnet" "private" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "${var.private_subnet_cidr_block}"
availability_zone = "${var.subnet_availability_zone}"
count = "${length(split(",", var.availability_zones))}"
availability_zone = "${element(split(",", var.availability_zones), count.index)}"
cidr_block = "10.0.${count.index+1}.0/24"
map_public_ip_on_launch = false
depends_on = ["aws_instance.bastion"]
tags {
Expand All @@ -24,6 +25,7 @@ resource "aws_route_table" "private" {

/* Associate the routing table to private subnet */
resource "aws_route_table_association" "private" {
subnet_id = "${aws_subnet.private.id}"
count = "${length(split(",", var.availability_zones))}"
subnet_id = "${element(aws_subnet.private.*.id, count.index)}"
route_table_id = "${aws_route_table.private.id}"
}
2 changes: 1 addition & 1 deletion terraform/aws/public-subnet.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_internet_gateway" "public" {
/* Public subnet */
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.default.id}"
availability_zone = "${var.subnet_availability_zone}"
availability_zone = "${var.public_subnet_availability_zone}"
cidr_block = "${var.public_subnet_cidr_block}"
map_public_ip_on_launch = true
depends_on = ["aws_internet_gateway.public"]
Expand Down
36 changes: 20 additions & 16 deletions terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ variable "key_file" {
default = ""
}

variable "private_key_file" {
description = "The ssh public key for using with the cloud provider."
default = ""
}

variable "atlas_infrastructure" {
description = "The Atlas infrastructure project to join."
default = "capgemini/infrastructure"
Expand All @@ -28,9 +33,14 @@ variable "region" {
default = "eu-west-1"
}

variable "subnet_availability_zone" {
description = "Availability zone for Apollo subnet."
default = "eu-west-1b"
variable "public_subnet_availability_zone" {
description = "Public availability zone."
default = ""
}

variable "availability_zones" {
description = "AWS availability zones list separated by ','"
default = ""
}

variable "vpc_cidr_block" {
Expand All @@ -43,11 +53,6 @@ variable "public_subnet_cidr_block" {
default = "10.0.0.0/24"
}

variable "private_subnet_cidr_block" {
description = "Cidr block for private Mesos subnet."
default = "10.0.1.0/24"
}

variable "slaves" {
description = "The number of slaves."
default = "1"
Expand All @@ -58,14 +63,6 @@ variable "masters" {
default = "3"
}

variable "master_ips" {
default = {
master-0 = "10.0.1.11"
master-1 = "10.0.1.12"
master-2 = "10.0.1.13"
}
}

variable "slave_block_device" {
description = "Block device for OSD."
default = {
Expand All @@ -87,6 +84,13 @@ variable "atlas_artifact" {
}
}

variable "atlas_artifact_version" {
default = {
master = "6"
slave = "6"
}
}

/* Base Ubuntu 14.04 amis by region */
variable "amis" {
description = "Base AMI to launch the instances with"
Expand Down