Skip to content

Commit

Permalink
Add deployment infra
Browse files Browse the repository at this point in the history
  • Loading branch information
iknite committed Feb 4, 2019
1 parent ace29e4 commit 2993ea6
Show file tree
Hide file tree
Showing 10 changed files with 451 additions and 0 deletions.
32 changes: 32 additions & 0 deletions deploy/aws/config.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

terraform {
required_version = ">= 0.11.11"
}

provider "aws" {
version = ">= 1.56.0, < 2.0"
profile = "${var.aws_profile}"
}

provider "http" {
version = ">= 1.0.1, < 2.0"
}

provider "null" {
version = "~> 2.0"
}
203 changes: 203 additions & 0 deletions deploy/aws/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module "leader" {
source = "./modules/qed"

name = "leader"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
server:
node_id: "leader"
addr:
http: ":8080"
mgmt: ":8090"
raft: ":9000"
gossip: ":9100"
CONFIG

}

module "follower-1" {
source = "./modules/qed"

name = "follower-1"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
server:
node_id: "follower-1"
addr:
http: ":8080"
mgmt: ":8090"
raft: ":9000"
gossip: ":9100"
raft_join:
- "${module.leader.private_ip}:9000"
gossip_join:
- "${module.leader.private_ip}:9100"
CONFIG

}

module "follower-2" {
source = "./modules/qed"

name = "follower-2"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
server:
node_id: "follower-2"
addr:
http: ":8080"
mgmt: ":8090"
raft: ":9000"
gossip: ":9100"
raft_join:
- "${module.leader.private_ip}:9000"
gossip_join:
- "${module.leader.private_ip}:9100"
CONFIG
}

module "inmemory-storage" {
source = "./modules/inmemory_storage"

name = "inmemory-storage"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"
}

module "agent-publisher" {
source = "./modules/qed"

name = "agent-publisher"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

command="agent"
config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
agent:
node: "publisher"
bind: ":9300"
advertise: ""
join:
- "${module.leader.private_ip}:9100"
server_urls:
- "${module.leader.private_ip}:8080"
alert_urls:
- "${module.inmemory-storage.private_ip}:8888"
snapshots_store_urls:
- "${module.inmemory-storage.private_ip}:8888"
CONFIG
}


module "agent-monitor" {
source = "./modules/qed"

name = "agent-monitor"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

command="agent"
config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
agent:
node: "monitor"
bind: ":9200"
advertise: ""
join:
- "${module.leader.private_ip}:9100"
server_urls:
- "${module.leader.private_ip}:8080"
alert_urls:
- "${module.inmemory-storage.private_ip}:8888"
snapshots_store_urls:
- "${module.inmemory-storage.private_ip}:8888"
CONFIG
}

module "agent-auditor" {
source = "./modules/qed"

name = "agent-auditor"
instance_type = "t2.2xlarge"
volume_size = "20"
vpc_security_group_ids = "${module.security_group.this_security_group_id}"
subnet_id = "${element(data.aws_subnet_ids.all.ids, 0)}"
key_name = "${aws_key_pair.qed.key_name}"

command="agent"
config = <<-CONFIG
---
api_key: "terraform_qed"
path: "/var/tmp/qed/"
agent:
node: "auditor"
bind: ":9100"
advertise: ""
join:
- "${module.leader.private_ip}:9100"
server_urls:
- "${module.leader.private_ip}:8080"
alert_urls:
- "${module.inmemory-storage.private_ip}:8888"
snapshots_store_urls:
- "${module.inmemory-storage.private_ip}:8888"
CONFIG
}
4 changes: 4 additions & 0 deletions deploy/aws/modules/inmemory_storage/data/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

#build inmemory storage
go build -o storage ../../../../../tests/gossip/test_service.go
Binary file added deploy/aws/modules/inmemory_storage/data/storage
Binary file not shown.
80 changes: 80 additions & 0 deletions deploy/aws/modules/inmemory_storage/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

data "aws_ami" "amazon_linux" {
most_recent = true

filter {
name = "name"
values = ["amzn-ami-hvm-*-x86_64-gp2"]
}

filter {
name = "owner-alias"
values = ["amazon"]
}
}

resource "null_resource" "prebuild" {
provisioner "local-exec" {
command = "bash build.sh"
working_dir = "${path.module}/data"
}
}


resource "aws_instance" "inmemory-storage" {
count = "1"
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "${var.instance_type}"

vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
subnet_id = "${var.subnet_id}"
associate_public_ip_address = true
key_name = "${var.key_name}"

root_block_device = [{
volume_type = "gp2"
volume_size = "${var.volume_size}"
}]

tags {
Name = "qed-${var.name}"
}


provisioner "file" {
source = "${path.module}/data"
destination = "${var.path}"

connection {
user = "ec2-user"
}
}

user_data = <<-DATA
#!/bin/bash
while [ ! -f ${var.path}/storage ]; do
sleep 1 # INFO: wait until binary is complete
done
while [ `lsof ${var.path}/storage | wc -l` -gt 0 ]; do
sleep 1 # INFO: prevents Error of `text file busy`
done
chmod +x ${var.path}/storage
${var.path}/storage
DATA
}
7 changes: 7 additions & 0 deletions deploy/aws/modules/inmemory_storage/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "private_ip" {
value = "${aws_instance.inmemory-storage.private_ip}"
}

output "public_ip" {
value = "${aws_instance.inmemory-storage.public_ip}"
}
31 changes: 31 additions & 0 deletions deploy/aws/modules/inmemory_storage/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

variable "instance_type" {}

variable "volume_size" {}

variable "vpc_security_group_ids" {}

variable "subnet_id" {}

variable "key_name" {}

variable "name" {}

variable "path" {
default = "/var/tmp/qed"
}
Loading

0 comments on commit 2993ea6

Please sign in to comment.