diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d955a86 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +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. \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e142b26 --- /dev/null +++ b/main.tf @@ -0,0 +1,26 @@ +resource "aws_elasticache_subnet_group" "default" { + name = "${var.namespace}-redis-subnet" + subnet_ids = var.subnet_ids + + tags = var.tags + +} + +resource "aws_elasticache_replication_group" "default" { + replication_group_id = var.cluster_id + replication_group_description = var.cluster_description + security_group_ids = [aws_security_group.redis-security-group.id] + node_type = var.node_type + port = var.port + parameter_group_name = var.parameter_group_name + + subnet_group_name = aws_elasticache_subnet_group.default.name + automatic_failover_enabled = var.automatic_failover_enabled + + cluster_mode { + replicas_per_node_group = var.replicas_per_node_group + num_node_groups = var.node_groups + } + + tags = var.tags +} diff --git a/output.tf b/output.tf new file mode 100644 index 0000000..257f6fe --- /dev/null +++ b/output.tf @@ -0,0 +1,15 @@ +output "primary_endpoint_address" { + value = "${aws_elasticache_replication_group.default.primary_endpoint_address}" +} + +output "arn" { + value = aws_elasticache_subnet_group.default.arn +} + +output "configuration_endpoint_address" { + value = aws_elasticache_replication_group.default.configuration_endpoint_address +} + +output "security_group_arn" { + value = aws_security_group.redis-security-group.arn +} \ No newline at end of file diff --git a/security-groups.tf b/security-groups.tf new file mode 100644 index 0000000..5ec8e1e --- /dev/null +++ b/security-groups.tf @@ -0,0 +1,21 @@ +# this security group for ecs - Traffic to the ECS cluster should only come from the ALB +resource "aws_security_group" "redis-security-group" { + name = var.security_group_name + vpc_id = var.vpc_id + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = var.tags +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..6e99d6d --- /dev/null +++ b/variables.tf @@ -0,0 +1,56 @@ +variable "namespace" { +} + +variable "node_groups" { + description = "Number of nodes groups to create in the" + default = 1 +} + +variable "cluster_id" { + description = "cluster name" + default = "redis-cluster" +} + +variable "cluster_description" { + description = "cluster description" + default = "" +} + +variable "port" { + description = "running port" + default = 6379 +} + +variable "automatic_failover_enabled" { + description = "" + default = true +} + +variable "security_group_name" { + description = "redis security group name" +} + +variable "replicas_per_node_group" { + description = "number of replicas run per node group" +} + +variable "parameter_group_name" { + description = "parameter group name" +} + +variable "node_type" { + description = "node type" +} + +variable "subnet_ids" { + description = "subnets" +} + +variable "vpc_id" { + description = "vpc id" +} + +variable "tags" { + description = "tags" + type = map(string) +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..2692e2e --- /dev/null +++ b/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.14.9" + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.27" + } + } +} \ No newline at end of file