Skip to content

Commit 935ce63

Browse files
committed
Split external_dependencies module into module for each infra component
1 parent e684416 commit 935ce63

26 files changed

+3445
-4909
lines changed

.terraform.lock.hcl

Lines changed: 0 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.terraform/modules/modules.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ec2_external-dependencies.tfvars

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ enable_ec2_deployment = true
22

33
enable_eks_deployment = false
44

5-
enable_external_dependencies = true
5+
#enable_external_dependencies = false
6+
7+
enable_elasticache = true
8+
9+
enable_rds = true
10+
11+
enable_s3 = true
612

713
s3_bucket_name = "cometml-use2"

external_dependencies_only.tfvars

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ enable_ec2_deployment = false
22

33
enable_eks_deployment = false
44

5-
enable_external_dependencies = true
5+
#enable_external_dependencies = true
6+
7+
enable_elasticache = true
8+
9+
enable_rds = true
10+
11+
enable_s3 = true
612

713
s3_bucket_name = "cometml-use2-tftest-dev"

main.tf

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module "eks_deployment" {
7070
cluster_version = var.eks_cluster_version
7171
}
7272

73+
/*
7374
module "external_dependencies" {
7475
source = "./modules/external_dependencies"
7576
count = var.enable_external_dependencies ? 1 : 0
@@ -80,7 +81,39 @@ module "external_dependencies" {
8081
8182
comet_ml_s3_bucket = var.s3_bucket_name
8283
84+
elasticache_rds_allowfrom_sg = module.ec2_deployment[0].allinone_sg_id
85+
}
86+
*/
87+
88+
module "comet_elasticache" {
89+
source = "./modules/comet_elasticache"
90+
count = var.enable_elasticache ? 1 : 0
91+
92+
vpc_id = module.vpc.vpc_id
93+
vpc_private_subnets = module.vpc.private_subnets
94+
95+
# need to get SGs from ec2_deployment or eks_deployment, depending on which is used
96+
# index is used on the ec2_deployment becuase of the count usage in the toggle: "After the count apply the resource becomes a group, so later in the reference use 0-index of the group"
97+
elasticache_rds_allowfrom_sg = module.ec2_deployment[0].allinone_sg_id
98+
}
99+
100+
module "comet_rds" {
101+
source = "./modules/comet_rds"
102+
count = var.enable_rds ? 1 : 0
103+
104+
availability_zones = local.azs
105+
vpc_id = module.vpc.vpc_id
106+
vpc_private_subnets = module.vpc.private_subnets
107+
83108
# need to get SGs from ec2_deployment or eks_deployment, depending on which is used
84109
# index is used on the ec2_deployment becuase of the count usage in the toggle: "After the count apply the resource becomes a group, so later in the reference use 0-index of the group"
85-
elasticcache_rds_allowfrom_sg = module.ec2_deployment[0].allinone_sg_id
110+
elasticache_rds_allowfrom_sg = module.ec2_deployment[0].allinone_sg_id
111+
112+
}
113+
114+
module "comet_s3" {
115+
source = "./modules/comet_s3"
116+
count = var.enable_s3 ? 1 : 0
117+
118+
comet_ml_s3_bucket = var.s3_bucket_name
86119
}

modules/comet_elasticache/README.md

Whitespace-only changes.

modules/comet_elasticache/main.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
locals {
2+
redis_port = 6379
3+
4+
tags = {
5+
Terraform_Managed = "true"
6+
Environment = var.environment
7+
}
8+
}
9+
10+
resource "aws_elasticache_cluster" "comet-ml-ec-redis" {
11+
cluster_id = "cometml-ec-redis-${var.environment}"
12+
engine = var.elasticache_engine
13+
node_type = var.elasticache_redis_instance_type
14+
num_cache_nodes = var.elasticache_num_cache_nodes
15+
parameter_group_name = var.elasticache_param_group_name
16+
engine_version = var.elasticache_engine_version
17+
port = local.redis_port
18+
subnet_group_name = aws_elasticache_subnet_group.comet-ml-ec-subnet-group.name
19+
# SG resource ref
20+
security_group_ids = [aws_security_group.redis_inbound_sg.id]
21+
}
22+
23+
resource "aws_elasticache_subnet_group" "comet-ml-ec-subnet-group" {
24+
name = "cometml-ec-sng-${var.environment}"
25+
subnet_ids = var.vpc_private_subnets
26+
}
27+
28+
resource "aws_security_group" "redis_inbound_sg" {
29+
name = "cometml_redis_in_sg_${var.environment}"
30+
description = "Redis Security Group"
31+
vpc_id = var.vpc_id
32+
}
33+
34+
resource "aws_vpc_security_group_ingress_rule" "redis_port_inbound_allow" {
35+
security_group_id = aws_security_group.redis_inbound_sg.id
36+
37+
from_port = local.redis_port
38+
to_port = local.redis_port
39+
ip_protocol = "tcp"
40+
# security groups need to change depending on whether Cx is using eks or ec2 deployment; hard-coded index won't work
41+
referenced_security_group_id = var.elasticache_rds_allowfrom_sg
42+
}

modules/comet_elasticache/outputs.tf

Whitespace-only changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
variable "environment" {
2+
description = "Deployment environment, i.e. dev/stage/prod, etc"
3+
type = string
4+
default = "dev"
5+
}
6+
7+
variable "elasticache_redis_instance_type" {
8+
description = "Elasticache Redis instance type"
9+
type = string
10+
default = "cache.r4.xlarge"
11+
}
12+
13+
variable "elasticache_engine" {
14+
description = "Engine type for Elasticache cluster"
15+
type = string
16+
default = "redis"
17+
}
18+
19+
variable "elasticache_engine_version" {
20+
description = "Version number for Elasticache engine"
21+
type = string
22+
default = "5.0.6"
23+
}
24+
25+
variable "elasticache_param_group_name" {
26+
description = "Name for the Elasticache cluster parameter group"
27+
type = string
28+
default = "default.redis5.0"
29+
}
30+
31+
variable "elasticache_num_cache_nodes" {
32+
description = "Number of nodes in the Elasticache cluster"
33+
type = number
34+
default = 1
35+
}
36+
37+
variable "vpc_id" {
38+
description = "ID of the VPC that will contain the provisioned resources"
39+
type = string
40+
default = ""
41+
}
42+
43+
variable "vpc_private_subnets" {
44+
description = "IDs of private subnets within the VPC"
45+
type = list(string)
46+
default = []
47+
}
48+
49+
variable "elasticache_rds_allowfrom_sg" {
50+
description = "Security group(s) attached to the Comet instance(s); Specified in the ingress allow rules on the Elasticache and RDS security groups"
51+
type = string
52+
default = ""
53+
}

modules/comet_elasticache/versions.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)