Skip to content

Commit dde8ed2

Browse files
added rediscluster for storing SF sessions
1 parent d6d5207 commit dde8ed2

File tree

6 files changed

+99
-4
lines changed

6 files changed

+99
-4
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ and the inline policy for the aim user terraform-bot-account
8888

8989
## deploy the infrastructure
9090

91+
Ensure the environment variables are loaded in your terminal sessions and that you are in the terraform directory.
92+
Then simply type:
93+
```
94+
make apply
95+
```
96+
97+
Warning: creating the redis cluster can take a significant amount of time (> 5 minutes). Just be patient and let it finish.
9198

9299
## useful commands for testing the infrastructure
93100

terraform/Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ show:
3333
terraform show
3434

3535
output:
36-
@echo "*** DOCKERNODES ***"
36+
@echo "\n*** DOCKERNODES ***"
3737
@terraform output --module=dockernodes
38-
@echo "*** LOADBALANCERS ***"
38+
@echo "\n*** LOADBALANCERS ***"
3939
@terraform output --module=loadbalancers
40-
@echo "*** MONGONODES *** "
40+
@echo "\n*** MONGONODES *** "
4141
@terraform output --module=mongodbnodes
42-
@echo "*** VPC ***"
42+
@echo "\n*** VPC ***"
4343
@terraform output --module=vpc
44+
@echo "\n*** Redis ***"
45+
@terraform output --module=rediscluster
4446

4547
ping:
4648
ansible -i bin/terraform.py/terraform.py -m ping all

terraform/main.tf

+16
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ module "mongodbnodes" {
5454
default_sg_id = "${module.vpc.default_sg_id}"
5555
subnet_id_zones = "${module.vpc.subnet_id_zones}"
5656
}
57+
58+
module "rediscluster" {
59+
source = "./redis"
60+
61+
env = "${var.env}"
62+
region = "${var.region}"
63+
vpc_id = "${module.vpc.vpc_id}"
64+
vpc_private_cidr = "${module.vpc.vpc_private_cidr}"
65+
subnet_id_zones = "${module.vpc.subnet_id_zones}"
66+
67+
cache_name = "redis-cache"
68+
engine_version = "2.8.22"
69+
instance_type = "cache.t2.micro"
70+
maintenance_window = "sun:05:00-sun:06:00"
71+
72+
}

terraform/redis/outputs.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "cache_security_group_id" {
2+
value = "${aws_security_group.redis.id}"
3+
}
4+
5+
output "hostname" {
6+
value = "${aws_elasticache_cluster.redis.cache_nodes.0.address}"
7+
}
8+
9+
output "port" {
10+
value = "${aws_elasticache_cluster.redis.cache_nodes.0.port}"
11+
}
12+
13+
output "endpoint" {
14+
value = "${format("%s:%s", aws_elasticache_cluster.redis.cache_nodes.0.address, aws_elasticache_cluster.redis.cache_nodes.0.port)}"
15+
}

terraform/redis/redis.tf

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "aws_security_group" "redis" {
2+
name = "redis_security_group"
3+
description = "Allowing access to redis cluster"
4+
vpc_id = "${var.vpc_id}"
5+
6+
}
7+
8+
resource "aws_elasticache_cluster" "redis" {
9+
cluster_id = "${var.cache_name}"
10+
engine = "redis"
11+
engine_version = "${var.engine_version}"
12+
maintenance_window = "${var.maintenance_window}"
13+
node_type = "${var.instance_type}"
14+
num_cache_nodes = "1"
15+
parameter_group_name = "default.redis2.8"
16+
port = "6379"
17+
subnet_group_name = "${aws_elasticache_subnet_group.default.name}"
18+
security_group_ids = ["${aws_security_group.redis.id}"]
19+
20+
tags {
21+
Name = "CacheCluster"
22+
env = "${var.env}"
23+
role = "redisnode"
24+
Name = "${format("redis-%02d", count.index + 1)}"
25+
}
26+
}
27+
28+
resource "aws_elasticache_subnet_group" "default" {
29+
name = "${var.cache_name}-subnet-group"
30+
description = "Private subnets for the ElastiCache instances"
31+
subnet_ids = ["${var.subnet_id_zones}"]
32+
}
33+
34+

terraform/redis/variables.tf

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "env" {}
2+
variable "region" {}
3+
4+
variable "vpc_id" {}
5+
variable "vpc_private_cidr" {}
6+
variable "subnet_id_zones" {
7+
type = "list"
8+
}
9+
variable "cache_name" {}
10+
11+
variable "engine_version" {
12+
default = "2.8.22"
13+
}
14+
15+
variable "instance_type" {
16+
default = "cache.t2.micro"
17+
}
18+
19+
variable "maintenance_window" {
20+
default = "sun:05:00-sun:06:00"
21+
}

0 commit comments

Comments
 (0)