diff --git a/infrastructure/elasticache.tf b/infrastructure/elasticache.tf new file mode 100644 index 00000000..b5553912 --- /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_elasticache_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" + 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 + } +} diff --git a/infrastructure/prod.tfvars b/infrastructure/prod.tfvars index 5d1bc555..4d03b446 100644 --- a/infrastructure/prod.tfvars +++ b/infrastructure/prod.tfvars @@ -103,3 +103,4 @@ ssm_redshift_host = "/crossfeed/prod/REDSHIFT_HOST" ssm_redshift_database = "/crossfeed/prod/REDSHIFT_DATABASE" ssm_redshift_user = "/crossfeed/prod/REDSHIFT_USER" ssm_redshift_password = "/crossfeed/prod/REDSHIFT_PASSWORD" +create_elasticache_cluster = false diff --git a/infrastructure/stage.tfvars b/infrastructure/stage.tfvars index e40e34f0..85720ffb 100644 --- a/infrastructure/stage.tfvars +++ b/infrastructure/stage.tfvars @@ -68,7 +68,6 @@ pe_worker_ecs_cluster_name = "pe-staging-worker" pe_worker_ecs_task_definition_family = "pe-staging-worker" pe_worker_ecs_log_group_name = "pe-staging-worker" pe_worker_ecs_role_name = "pe-staging-worker" -pe_cybersixgill_ecs_service_name = "pe-staging-cybersixgill" logging_bucket_name = "cisa-crossfeed-staging-logging" cloudtrail_name = "crossfeed-staging-all-events" cloudtrail_bucket_name = "cisa-crossfeed-staging-cloudtrail" @@ -105,3 +104,4 @@ ssm_redshift_host = "/crossfeed/staging/REDSHIFT_HOST" ssm_redshift_database = "/crossfeed/staging/REDSHIFT_DATABASE" ssm_redshift_user = "/crossfeed/staging/REDSHIFT_USER" ssm_redshift_password = "/crossfeed/staging/REDSHIFT_PASSWORD" +create_elasticache_cluster = true diff --git a/infrastructure/vars.tf b/infrastructure/vars.tf index f920dc56..36cf07b7 100644 --- a/infrastructure/vars.tf +++ b/infrastructure/vars.tf @@ -656,3 +656,9 @@ variable "ssm_redshift_password" { type = string default = "/crossfeed/staging/REDSHIFT_PASSWORD" } + +variable "create_elasticache_cluster" { + description = "Whether to create a elasticache cluster." + type = bool + default = false +}