Skip to content
This repository was archived by the owner on Oct 8, 2022. It is now read-only.

Added support for existing subnet group and security group #18

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
locals {
subnet_tag_name = "Type"
}

data "aws_vpc" "selected" {
filter {
name = "tag:${var.vpc_tag_name}"
values = ["${var.vpc_name}${var.vpc_tag_value}"]
}
}

data "aws_subnet_ids" "private" {
vpc_id = "${data.aws_vpc.selected.id}"

filter {
name ="tag:${var.vpc_subnet_tag_name}"
values = ["${var.vpc_subnet_tag_value}"]
}

}

data "aws_security_group" "default" {
// This is to use our existing security group for access from the hopper
filter {
name = "${var.sg_filter_name}"
values = ["${var.sg_filter_value}"]
}

filter {
name = "vpc-id"
values = ["${data.aws_vpc.selected.id}"]
}
}
11 changes: 9 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -11,6 +11,13 @@ resource "aws_security_group" "redis" {
}
}

resource "aws_elasticache_subnet_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "subnet-group-${lower(var.cache_identifier)}"
description = "Private subnets for the ElastiCache instances: ${lower(var.cache_identifier)}"
subnet_ids = ["${data.aws_subnet_ids.private.ids}"]
}

#
# ElastiCache resources
#
@@ -22,8 +29,8 @@ resource "aws_elasticache_replication_group" "redis" {
node_type = "${var.instance_type}"
engine_version = "${var.engine_version}"
parameter_group_name = "${var.parameter_group}"
subnet_group_name = "${var.subnet_group}"
security_group_ids = ["${aws_security_group.redis.id}"]
subnet_group_name = "${var.subnet_group == "" ? aws_elasticache_subnet_group.default.name : var.subnet_group }"
security_group_ids = ["${aws_security_group.redis.id},${data.aws_security_group.default.id}"]
maintenance_window = "${var.maintenance_window}"
notification_topic_arn = "${var.notification_topic_arn}"
port = "6379"
34 changes: 30 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -8,15 +8,40 @@ variable "environment" {

variable "vpc_id" {}

variable "vpc_name" {
description = "Provide vpc name for your region"
}

variable "vpc_tag_name" {}
variable "vpc_tag_value" {}
variable "vpc_subnet_tag_name" {}
variable "vpc_subnet_tag_value" {}

variable "sg_filter_name" {
default = "description"
}

variable "sg_filter_value" {
default = ""
}

variable "enabled" {
description = "Set to false to prevent the module from creating any resources"
default = "true"
}

variable "cache_identifier" {}

variable "parameter_group" {
default = "default.redis3.2"
}

variable "subnet_group" {}
variable "subnet_group" {
default = "cloud-elast-19f609hoj8an"
}

variable "maintenance_window" {}
variable "maintenance_window" {
}

variable "desired_clusters" {
default = "1"
@@ -34,7 +59,8 @@ variable "automatic_failover_enabled" {
default = false
}

variable "notification_topic_arn" {}
variable "notification_topic_arn" {
}

variable "alarm_cpu_threshold" {
default = "75"
@@ -46,5 +72,5 @@ variable "alarm_memory_threshold" {
}

variable "alarm_actions" {
type = "list"
type = "list"
}