From 169f97d69fa514a6ef28bf1263bd462a3c6ccdfb Mon Sep 17 00:00:00 2001 From: cduhn17 Date: Mon, 8 Jul 2024 12:17:29 -0500 Subject: [PATCH] Add elasticache tf file --- infrastructure/elasticache.tf | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 infrastructure/elasticache.tf diff --git a/infrastructure/elasticache.tf b/infrastructure/elasticache.tf new file mode 100644 index 00000000..dba16374 --- /dev/null +++ b/infrastructure/elasticache.tf @@ -0,0 +1,39 @@ +resource "aws_security_group" "elasticache_security_group" { + name_prefix = "elasticache-" + description = "ElastiCache security group" + + ingress { + from_port = 6379 + to_port = 6379 + protocol = "tcp" + cidr_blocks = ["10.0.2.0/24"] // Restrict to a specific CIDR block, ideally your VPC's CIDR + } +} + +resource "aws_elasticache_subnet_group" "crossfeed_vpc" { + name = "aws_vpc.crossfeed_vpc" + subnet_ids = [aws_subnet.backend.id] + + tags = { + Name = "crossfeed_vpc" + } +} + +resource "aws_elasticache_cluster" "crossfeed_vpc_elasticache_cluster" { + count = var.create_elastcache_cluster ? 1 : 0 + cluster_id = "crossfeed-vpc-cluster" + engine = "redis" + node_type = "cache.r7g.xlarge" + num_cache_nodes = 1 + parameter_group_name = "default.redis7.1" + engine_version = "7.1.0" + port = 6379 + subnet_group_name = aws_elasticache_subnet_group.crossfeed_vpc.name + security_group_ids = [aws_security_group.elasticache_security_group.id] + + tags = { + Name = "crossfeed_vpc_elasticache-cluster" + Project = var.project + Stage = var.stage + } +} \ No newline at end of file