Skip to content
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
8 changes: 4 additions & 4 deletions bootstrap/aws-public/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ 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:-6}
export TF_VAR_atlas_artifact_version_slave=${TF_VAR_atlas_artifact_version_slave:-6}
export TF_VAR_atlas_artifact_version_master=${TF_VAR_atlas_artifact_version_master:-8}
export TF_VAR_atlas_artifact_version_slave=${TF_VAR_atlas_artifact_version_slave:-8}

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_master_size=${TF_VAR_master_size:-m3.medium}
export TF_VAR_slave_size=${TF_VAR_slave_size:-m3.medium}
export TF_VAR_slaves=${TF_VAR_slaves:-1}
export TF_VAR_availability_zones=${TF_VAR_availability_zones:-'eu-west-1a,eu-west-1b,eu-west-1c'}

Expand Down
10 changes: 9 additions & 1 deletion terraform/aws-public/mesos-masters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ resource "atlas_artifact" "mesos-master" {

/* Mesos master instances */
resource "aws_instance" "mesos-master" {
/*
We had to hardcode the amis list in variables.tf file creating amis map because terraform doesn't
support interpolation in the way which could allow us to replaced the region dinamically.
We need to remember to update the map every time when we build a new artifact on atlas.
Similar issue related to metada_full is mentioned here:
https://github.com/hashicorp/terraform/issues/732
*/

instance_type = "${var.instance_type.master}"
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
ami = "${lookup(var.amis, var.region)}"
count = "${var.masters}"
key_name = "${aws_key_pair.deployer.key_name}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
Expand Down
10 changes: 9 additions & 1 deletion terraform/aws-public/mesos-slaves.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ resource "atlas_artifact" "mesos-slave" {

/* Mesos slave instances */
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment here exaplaining why is this being harcoded and linking to terraform issue?

Copy link
Member

Choose a reason for hiding this comment

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

could we not do some kind of map here in the variables?

amis = {
 eu-west-1 => 'ami-123',
 us-east-1 => 'ami-456',
}

etc..

and then use that var to replace on the end..

 "${atlas_artifact.mesos-master.metadata_full.region-${var.amis.${region}}}"

above code is syntactically incorrect but you get the gist

or even just use the region string without the AMi map? -

varname = "atlas_artifact.mesos-master.metadata_full.region-${var.region}”

ami = ${varname}

Copy link
Contributor

Choose a reason for hiding this comment

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

Dont think that interpolation is supported by terraform. -> "${atlas_artifact.mesos-master.metadata_full.region-${var.amis.${region}}}"

Think we can harcode it as ${atlas_artifact.mesos-master.metadata_full.region-eu-west-1}
or create a static map region -> ami-id
Then just ami = lookup(var.amis, var.region)

Static mapping would need to be updated every time we build images and the atlas_artifact resource shoudl be removed as it would be useless if we go for second option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As enxebre mentioned the interpolation is not supported by terraform. I tested it with terraform version 0.6.1 (the newest one). So the code:

varname = "atlas_artifact.mesos-master.metadata_full.region-${var.region}”

ami = ${varname}

and my version mentioned in the terraform ticket:

ami = "${lookup(atlas_artifact.mesos-master.metadata_full, concat("region-", var.region))}"

don't work.

resource "aws_instance" "mesos-slave" {
/*
We had to hardcode the amis list in variables.tf file creating amis map because terraform doesn't
support interpolation in the way which could allow us to replaced the region dinamically.
We need to remember to update the map every time when we build a new artifact on atlas.
Similar issue related to metada_full is mentioned here:
https://github.com/hashicorp/terraform/issues/732
*/

instance_type = "${var.instance_type.slave}"
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
ami = "${lookup(var.amis, var.region)}"
count = "${var.slaves}"
key_name = "${aws_key_pair.deployer.key_name}"
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
Expand Down
23 changes: 19 additions & 4 deletions terraform/aws-public/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ variable "slave_block_device" {

variable "instance_type" {
default = {
master = "m1.medium"
slave = "m1.medium"
master = "m3.medium"
slave = "m3.medium"
}
}

Expand All @@ -76,7 +76,22 @@ variable "atlas_artifact" {

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

/* Remember to update the list every time when you build a new artifact on atlas */
variable "amis" {
default = {
ap-northeast-1 = "ami-249e2e24"
ap-southeast-1 = "ami-f20b06a0"
ap-southeast-2 = "ami-7d793847"
eu-central-1 = "ami-f6888deb"
eu-west-1 = "ami-8c6431fb"
sa-east-1 = "ami-158b0508"
us-east-1 = "ami-2f36ee44"
us-west-1 = "ami-1d6d9059"
us-west-2 = "ami-af323d9f"
}
}
10 changes: 9 additions & 1 deletion terraform/aws/mesos-masters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ resource "atlas_artifact" "mesos-master" {

/* Mesos master instances */
resource "aws_instance" "mesos-master" {
/*
We had to hardcode the amis list in variables.tf file creating amis map because terraform doesn't
support interpolation in the way which could allow us to replaced the region dinamically.
We need to remember to update the map every time when we build a new artifact on atlas.
Similar issue related to metada_full is mentioned here:
https://github.com/hashicorp/terraform/issues/732
*/

instance_type = "${var.instance_type.master}"
ami = "${replace(atlas_artifact.mesos-master.id, concat(var.region, ":"), "")}"
ami = "${lookup(var.amis, var.region)}"
count = "${var.masters}"
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
Expand Down
12 changes: 10 additions & 2 deletions terraform/aws/mesos-slaves.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ resource "atlas_artifact" "mesos-slave" {

/* Mesos slave instances */
resource "aws_instance" "mesos-slave" {
/*
We had to hardcode the amis list in variables.tf file creating amis map because terraform doesn't
support interpolation in the way which could allow us to replaced the region dinamically.
We need to remember to update the map every time when we build a new artifact on atlas.
Similar issue related to metada_full is mentioned here:
https://github.com/hashicorp/terraform/issues/732
*/

instance_type = "${var.instance_type.slave}"
ami = "${replace(atlas_artifact.mesos-slave.id, concat(var.region, ":"), "")}"
ami = "${lookup(var.amis, var.region)}"
count = "${var.slaves}"
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
Expand Down Expand Up @@ -54,4 +62,4 @@ resource "aws_elb" "app" {
resource "aws_proxy_protocol_policy" "http" {
load_balancer = "${aws_elb.app.name}"
instance_ports = ["80"]
}
}
21 changes: 14 additions & 7 deletions terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ variable "slave_block_device" {

variable "instance_type" {
default = {
master = "m1.medium"
slave = "m1.medium"
master = "m3.medium"
slave = "m3.medium"
}
}

Expand All @@ -86,16 +86,23 @@ variable "atlas_artifact" {

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

/* Base Ubuntu 14.04 amis by region */
/* Remember to update the list every time when you build a new artifact on atlas */
variable "amis" {
description = "Base AMI to launch the instances with"
default = {
eu-west-1 = "ami-234ecc54"
ap-northeast-1 = "ami-249e2e24"
ap-southeast-1 = "ami-f20b06a0"
ap-southeast-2 = "ami-7d793847"
eu-central-1 = "ami-f6888deb"
eu-west-1 = "ami-8c6431fb"
sa-east-1 = "ami-158b0508"
us-east-1 = "ami-2f36ee44"
us-west-1 = "ami-1d6d9059"
us-west-2 = "ami-af323d9f"
}
}