Skip to content

Commit

Permalink
Update metamon
Browse files Browse the repository at this point in the history
  • Loading branch information
bensojona committed Aug 15, 2015
1 parent 94bb618 commit 4e464cd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion metamon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ _\** `packer push metamon.json` will rebuild the AMI with the application code t
2. Navigate to the [ops/terraform](ops/terraform) directory on the command line.
3. Run `terraform remote config -backend-config name=<your_atlas_username>/metamon` in the [ops/terraform](ops/terraform) directory, replacing `<your_atlas_username>` with your Atlas username to configure [remote state storage](https://www.terraform.io/docs/commands/remote-config.html) for this infrastructure. Now when you run Terraform, the infrastructure state will be saved in Atlas, keeping a versioned history of your infrastructure.
4. Get the latest modules by running `terraform get` in the [ops/terraform](ops/terraform) directory.
5. Run `terraform push -name <your_atlas_username>/metamon` in the [ops/terraform](ops/terraform) directory, replacing `<your_atlas_username>` with your Atlas username.
5. Run `terraform push -name <your_atlas_username>/metamon` in the [ops/terraform](ops/terraform) directory, replacing `<your_atlas_username>` with your Atlas username. Make sure that your files are checked into version control or add the switch [`-vcs=false`](https://www.terraform.io/docs/commands/push.html) to the `terraform push` command.
6. Go to the [Environments tab](https://atlas.hashicorp.com/environments) in your Atlas account and click on the "metamon" environment. Navigate to "Changes" on the left side panel of the environment, click on the latest "Run" and wait for the "plan" to finish, then click "Confirm & Apply" to deploy your Metamon web app and Consul cluster.
![Confirm & Apply](screenshots/environments_changes_confirm.png?raw=true)
7. You should see 4 new boxes spinning up in EC2, one named "metamon\_1", which is your web app, and three named "consul\_n", which are the nodes in your Consul cluster.
Expand Down
2 changes: 1 addition & 1 deletion metamon/ops/packer/consul.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"subnet_id": "subnet-8f1e5ba4",
"ssh_username": "ubuntu",
"source_ami": "ami-9a562df2",
"atlas_username": "jb_hashicorp",
"atlas_username": "{{env `ATLAS_USERNAME`}}",
"atlas_build_name": "consul"
},
"builders": [
Expand Down
2 changes: 1 addition & 1 deletion metamon/ops/packer/metamon.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"subnet_id": "subnet-8f1e5ba4",
"ssh_username": "ubuntu",
"source_ami": "ami-9a562df2",
"atlas_username": "jb_hashicorp",
"atlas_username": "{{env `ATLAS_USERNAME`}}",
"atlas_build_name": "metamon"
},
"builders": [
Expand Down
16 changes: 9 additions & 7 deletions metamon/ops/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ resource "aws_key_pair" "consul" {
module "network" {
source = "./network"

name = "${var.atlas_environment}"
source_cidr_block = "${var.source_cidr_block}"
availability_zone = "${var.availability_zone}"
}
Expand All @@ -59,7 +60,7 @@ module "sg_web" {
aws_access_key = "${var.aws_access_key}"
aws_secret_key = "${var.aws_secret_key}"
aws_region = "${var.region}"
security_group_name = "allow_web"
security_group_name = "${var.atlas_environment}.allow_web"
source_cidr_block = "0.0.0.0/0"
}

Expand All @@ -70,7 +71,7 @@ module "sg_consul" {
aws_access_key = "${var.aws_access_key}"
aws_secret_key = "${var.aws_secret_key}"
aws_region = "${var.region}"
security_group_name = "allow_consul"
security_group_name = "${var.atlas_environment}.allow_consul"
source_cidr_block = "0.0.0.0/0"
}

Expand Down Expand Up @@ -98,8 +99,7 @@ resource "aws_instance" "metamon" {
"${module.sg_consul.security_group_id}"
]

tags { Name = "metamon_${count.index+1}" }
lifecycle = { create_before_destroy = true }
tags { Name = "metamon.${count.index+1}" }
}
Expand All @@ -111,8 +111,10 @@ resource "aws_instance" "consul" {
availability_zone = "${var.availability_zone}"
count = "${var.consul_server_count}"
subnet_id = "${module.network.subnet_id}"
vpc_security_group_ids = ["${module.sg_consul.security_group_id}"]
vpc_security_group_ids = [
"${module.sg_web.security_group_id_web}",
"${module.sg_consul.security_group_id}"
]

tags { Name = "consul_${count.index+1}" }
lifecycle = { create_before_destroy = true }
tags { Name = "consul.${count.index+1}" }
}
9 changes: 9 additions & 0 deletions metamon/ops/terraform/network/main.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
variable "name" {}
variable "source_cidr_block" {}
variable "availability_zone" {}

resource "aws_vpc" "mod" {
cidr_block = "${var.source_cidr_block}/16"
enable_dns_hostnames = true

tags { Name = "${var.name}" }
}
resource "aws_subnet" "mod" {
vpc_id = "${aws_vpc.mod.id}"
cidr_block = "${var.source_cidr_block}/20"
availability_zone = "${var.availability_zone}"
map_public_ip_on_launch = true

tags { Name = "${var.name}" }
}
resource "aws_internet_gateway" "mod" {
vpc_id = "${aws_vpc.mod.id}"

tags { Name = "${var.name}" }
}
resource "aws_route_table" "mod" {
vpc_id = "${aws_vpc.mod.id}"

route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.mod.id}"
}
tags { Name = "${var.name}" }
}
resource "aws_main_route_table_association" "mod" {
Expand Down
2 changes: 1 addition & 1 deletion metamon/ops/terraform/scripts/consul_upstart.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

sed -i -- "s/{{ atlas_username }}/${atlas_username}/g" /etc/init/consul.conf
sed -i -- "s/{{ atlas_token }}/${atlas_user_token}/g" /etc/init/consul.conf
sed -i -- "s/{{ atlas_token }}/${atlas_token}/g" /etc/init/consul.conf
sed -i -- "s/{{ atlas_environment }}/${atlas_environment}/g" /etc/init/consul.conf
sed -i -- "s/{{ consul_server_count }}/${consul_server_count}/g" /etc/init/consul.conf
service consul restart
Expand Down
5 changes: 1 addition & 4 deletions metamon/ops/terraform/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ command line like below or set them as environment variables.
terraform remote config -backend-config name=$ATLAS_USERNAME/metamon
terraform get
terraform push -name $ATLAS_USERNAME/metamon_1 \
terraform push -name $ATLAS_USERNAME/metamon \
-var "atlas_username=$ATLAS_USERNAME" \
-var "atlas_token=$ATLAS_TOKEN" \
-var "aws_access_key=$AWS_ACCESS_KEY_ID" \
-var "aws_secret_key=$AWS_SECRET_ACCESS_KEY"
See https://www.terraform.io/intro/getting-started/variables.html */

# Required Variables
atlas_username = "jb_hashicorp"

atlas_environment = "metamon"
region = "us-east-1"
availability_zone = "us-east-1a"
Expand Down

0 comments on commit 4e464cd

Please sign in to comment.