Commit 8e140c99 authored by A-Gordon's avatar A-Gordon

Initial commit

parents
image: alpine:latest
variables:
TERRAFORM_URL: "https://releases.hashicorp.com/terraform/0.7.1/terraform_0.7.1_linux_amd64.zip"
before_script:
- apk update && apk add ca-certificates && update-ca-certificates && apk add openssl
- wget -O /tmp/terraform.zip $TERRAFORM_URL
- unzip /tmp/terraform.zip -d /usr/local/bin
test:
script: terraform validate
#############################################################################################################
# Variables
#############################################################################################################
variable "vpc_id" {}
variable "security_groups" {
type = "list"
}
variable "subnet_ids" {
type = "list"
}
variable "cache_name" {}
variable "cache_nodes" {
default = "2"
}
variable "az_mode" {
default = "cross-az"
}
variable "engine_version" {
default = "1.4.24"
}
variable "instance_type" {
default = "cache.t2.micro"
}
variable "port" {
default = "11211"
}
variable "maintenance_window" {
default = "sun:01:00-sun:02:00"
}
variable "dns_zone" {}
# variable "alarm_actions" {}
############################################################################################################
# Security Group
#############################################################################################################
resource "aws_security_group" "memcached" {
vpc_id = "${var.vpc_id}"
description = "ElastiCache SG"
ingress {
from_port = 11211
to_port = 11211
protocol = "tcp"
security_groups = ["${var.security_groups}"]
}
tags = {
Name = "${var.cache_name}"
}
}
############################################################################################################
# Subnet Group
#############################################################################################################
resource "aws_elasticache_subnet_group" "default" {
name = "${var.cache_name}-subnet-group"
description = "Private subnets for the ElastiCache instances"
subnet_ids = ["${var.subnet_ids}"]
}
############################################################################################################
# Elasticache Cluster
#############################################################################################################
resource "aws_elasticache_cluster" "memcached" {
cluster_id = "${var.cache_name}"
engine = "memcached"
engine_version = "${var.engine_version}"
maintenance_window = "${var.maintenance_window}"
node_type = "${var.instance_type}"
num_cache_nodes = "${var.cache_nodes}"
az_mode = "${var.az_mode}"
parameter_group_name = "default.memcached1.4"
port = "${var.port}"
subnet_group_name = "${aws_elasticache_subnet_group.default.name}"
security_group_ids = ["${aws_security_group.memcached.id}"]
tags {
Name = "CacheCluster"
}
}
############################################################################################################
# Route53 record
#############################################################################################################
resource "aws_route53_record" "memcached" {
zone_id = "${var.dns_zone}"
name = "cache.cfg.${var.cache_name}.aws"
type = "CNAME"
ttl = "60"
records = ["${aws_elasticache_cluster.memcached.cluster_address}"]
}
############################################################################################################
# Cloudwatch resources
#############################################################################################################
resource "aws_cloudwatch_metric_alarm" "cpu" {
alarm_name = "alarmCacheClusterCPUUtilization"
alarm_description = "Cache cluster CPU utilization"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "CPUUtilization"
namespace = "AWS/ElastiCache"
period = "300"
statistic = "Average"
threshold = "75"
dimensions {
CacheClusterId = "${aws_elasticache_cluster.memcached.id}"
}
# alarm_actions = ["${split(",", var.alarm_actions)}"]
}
resource "aws_cloudwatch_metric_alarm" "memory_free" {
alarm_name = "alarmCacheClusterFreeableMemory"
alarm_description = "Cache cluster freeable memory"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "FreeableMemory"
namespace = "AWS/ElastiCache"
period = "60"
statistic = "Average"
# 10MB in bytes
threshold = "10000000"
dimensions {
CacheClusterId = "${aws_elasticache_cluster.memcached.id}"
}
# alarm_actions = ["${split(",", var.alarm_actions)}"]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment