Skip to content

Commit f807a2c

Browse files
committed
expose vars from comet_rds into root
1 parent f931b94 commit f807a2c

File tree

5 files changed

+187
-101
lines changed

5 files changed

+187
-101
lines changed

comet-infrastructure/main.tf

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ module "comet_ec2" {
5353
count = var.enable_ec2 ? 1 : 0
5454
environment = var.environment
5555

56-
vpc_id = module.vpc.vpc_id
57-
comet_ec2_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
58-
56+
vpc_id = module.vpc.vpc_id
57+
comet_ec2_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
5958
comet_ec2_ami = var.comet_ec2_ami
6059
comet_ec2_instance_type = var.comet_ec2_instance_type
6160
comet_ec2_instance_count = var.comet_ec2_instance_count
@@ -71,14 +70,12 @@ module "comet_ec2" {
7170
}
7271

7372
module "comet_ec2_alb" {
74-
source = "./modules/comet_ec2_alb"
75-
count = var.enable_ec2_alb ? 1 : 0
76-
73+
source = "./modules/comet_ec2_alb"
74+
count = var.enable_ec2_alb ? 1 : 0
7775
environment = var.environment
7876

79-
vpc_id = module.vpc.vpc_id
80-
public_subnets = module.vpc.public_subnets
81-
77+
vpc_id = module.vpc.vpc_id
78+
public_subnets = module.vpc.public_subnets
8279
ssl_certificate_arn = var.enable_ec2_alb ? var.ssl_certificate_arn : null
8380
}
8481

@@ -132,18 +129,26 @@ module "comet_rds" {
132129
ec2_enabled = var.enable_ec2
133130
eks_enabled = var.enable_eks
134131

135-
availability_zones = local.azs
136-
vpc_id = module.vpc.vpc_id
137-
vpc_private_subnets = module.vpc.private_subnets
138-
rds_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
139-
rds_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
140-
rds_root_password = var.rds_root_password
132+
availability_zones = local.azs
133+
vpc_id = module.vpc.vpc_id
134+
rds_private_subnets = module.vpc.private_subnets
135+
rds_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
136+
rds_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
137+
rds_engine = var.rds_engine
138+
rds_engine_version = var.rds_engine_version
139+
rds_instance_type = var.rds_instance_type
140+
rds_instance_count = var.rds_instance_count
141+
rds_storage_encrypted = var.rds_storage_encrypted
142+
rds_iam_db_auth = var.rds_iam_db_auth
143+
rds_backup_retention_period = var.rds_backup_retention_period
144+
rds_preferred_backup_window = var.rds_preferred_backup_window
145+
rds_database_name = var.rds_database_name
146+
rds_root_password = var.rds_root_password
141147
}
142148

143149
module "comet_s3" {
144-
source = "./modules/comet_s3"
145-
count = var.enable_s3 ? 1 : 0
146-
150+
source = "./modules/comet_s3"
151+
count = var.enable_s3 ? 1 : 0
147152
environment = var.environment
148153

149154
comet_s3_bucket = var.s3_bucket_name

comet-infrastructure/modules/comet_rds/main.tf

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,124 @@ locals {
22
mysql_port = 3306
33

44
tags = {
5-
Terraform = "true"
6-
Environment = var.environment
5+
Terraform = "true"
6+
Environment = var.environment
77
}
88
}
99

1010
resource "aws_db_subnet_group" "comet-ml-rds-subnet" {
11-
name = "cometml_rds_sgn_${var.environment}"
12-
subnet_ids = var.vpc_private_subnets
13-
tags = merge(local.tags, {
14-
Name = "cometml-rds_sng-${var.environment}"
11+
name = "cometml-rds-sgn-${var.environment}"
12+
subnet_ids = var.rds_private_subnets
13+
tags = merge(local.tags, {
14+
Name = "cometml-rds-sng-${var.environment}"
1515
})
1616
}
1717

1818
resource "aws_rds_cluster_instance" "comet-ml-rds-mysql" {
1919
count = var.rds_instance_count
20-
identifier = "cometml-mysql-${var.environment}-${count.index}"
21-
cluster_identifier = aws_rds_cluster.comet-ml-cluster.id
20+
identifier = "cometml-rds-${var.environment}-${count.index}"
21+
cluster_identifier = aws_rds_cluster.cometml-db-cluster.id
2222
instance_class = var.rds_instance_type
2323
engine = var.rds_engine
2424
engine_version = var.rds_engine_version
2525
}
2626

2727

28-
resource "aws_rds_cluster" "comet-ml-cluster" {
29-
cluster_identifier = "cometml-mysql-cluster-${var.environment}"
30-
db_subnet_group_name = aws_db_subnet_group.comet-ml-rds-subnet.name
28+
resource "aws_rds_cluster" "cometml-db-cluster" {
29+
cluster_identifier = "cometml-rds-cluster-${var.environment}"
30+
db_subnet_group_name = aws_db_subnet_group.comet-ml-rds-subnet.name
3131
availability_zones = var.availability_zones
32-
database_name = "logger"
33-
storage_encrypted = true
34-
iam_database_authentication_enabled = true
32+
database_name = var.rds_database_name
33+
storage_encrypted = var.rds_storage_encrypted
34+
iam_database_authentication_enabled = var.rds_iam_db_auth
3535
master_username = "root"
3636
master_password = var.rds_root_password
3737
engine = var.rds_engine
3838
engine_version = var.rds_engine_version
39-
backup_retention_period = 7
40-
final_snapshot_identifier = "comet-ml-rds-backup-${var.environment}"
41-
preferred_backup_window = "07:00-09:00"
39+
backup_retention_period = var.rds_backup_retention_period
40+
final_snapshot_identifier = "cometml-rds-backup-${var.environment}"
41+
preferred_backup_window = var.rds_preferred_backup_window
4242
vpc_security_group_ids = [aws_security_group.mysql_sg.id]
43-
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.comet-ml-cluster-pg.name
43+
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.cometml-cluster-pg.name
4444
}
4545

46-
resource "aws_rds_cluster_parameter_group" "comet-ml-cluster-pg" {
46+
resource "aws_rds_cluster_parameter_group" "cometml-cluster-pg" {
4747
name = "cometml-rds-cluster-pg-${var.environment}"
4848
family = "aurora-mysql5.7"
49-
description = "Comet ML RDS cluster parameter group"
49+
description = "CometML RDS cluster parameter group"
5050

5151
parameter {
5252
apply_method = "pending-reboot"
53-
name = "character_set_server"
54-
value = "utf8mb4"
53+
name = "character_set_server"
54+
value = "utf8mb4"
5555
}
5656
parameter {
5757
apply_method = "pending-reboot"
58-
name = "character_set_connection"
59-
value = "utf8mb4"
58+
name = "character_set_connection"
59+
value = "utf8mb4"
6060
}
6161
parameter {
6262
apply_method = "pending-reboot"
63-
name = "character_set_database"
64-
value = "utf8mb4"
63+
name = "character_set_database"
64+
value = "utf8mb4"
6565
}
6666
parameter {
6767
apply_method = "pending-reboot"
68-
name = "character_set_results"
69-
value = "utf8mb4"
68+
name = "character_set_results"
69+
value = "utf8mb4"
7070
}
7171
parameter {
7272
apply_method = "pending-reboot"
73-
name = "collation_connection"
74-
value = "utf8mb4_unicode_ci"
73+
name = "collation_connection"
74+
value = "utf8mb4_unicode_ci"
7575
}
7676
parameter {
7777
apply_method = "pending-reboot"
78-
name = "collation_server"
79-
value = "utf8mb4_unicode_ci"
78+
name = "collation_server"
79+
value = "utf8mb4_unicode_ci"
8080
}
8181
parameter {
8282
apply_method = "pending-reboot"
83-
name = "innodb_flush_log_at_trx_commit"
84-
value = "1"
83+
name = "innodb_flush_log_at_trx_commit"
84+
value = "1"
8585
}
8686
parameter {
8787
apply_method = "pending-reboot"
88-
name = "innodb_lock_wait_timeout"
89-
value = "120"
88+
name = "innodb_lock_wait_timeout"
89+
value = "120"
9090
}
9191
parameter {
9292
apply_method = "pending-reboot"
93-
name = "max_allowed_packet"
94-
value = "157286400"
93+
name = "max_allowed_packet"
94+
value = "157286400"
9595
}
9696
parameter {
9797
apply_method = "pending-reboot"
98-
name = "thread_stack"
99-
value = "2000000"
98+
name = "thread_stack"
99+
value = "2000000"
100100
}
101101
}
102102

103103
resource "aws_security_group" "mysql_sg" {
104104
name = "${var.environment}_mysql_sg"
105-
description = "Aurora MySQL RDS Security Group"
106-
vpc_id = var.vpc_id
105+
description = "CometML RDS cluster security group"
106+
vpc_id = var.vpc_id
107107
}
108108

109109
resource "aws_vpc_security_group_ingress_rule" "mysql_port_inbound_ec2" {
110-
count = var.ec2_enabled ? 1 : 0
111-
security_group_id = aws_security_group.mysql_sg.id
112-
113-
from_port = local.mysql_port
114-
to_port = local.mysql_port
115-
ip_protocol = "tcp"
110+
count = var.ec2_enabled ? 1 : 0
111+
security_group_id = aws_security_group.mysql_sg.id
112+
from_port = local.mysql_port
113+
to_port = local.mysql_port
114+
ip_protocol = "tcp"
116115
referenced_security_group_id = var.rds_allow_ec2_sg
117116
}
118117

119118
resource "aws_vpc_security_group_ingress_rule" "mysql_port_inbound_eks" {
120-
count = var.eks_enabled ? 1 : 0
121-
security_group_id = aws_security_group.mysql_sg.id
122-
123-
from_port = local.mysql_port
124-
to_port = local.mysql_port
125-
ip_protocol = "tcp"
119+
count = var.eks_enabled ? 1 : 0
120+
security_group_id = aws_security_group.mysql_sg.id
121+
from_port = local.mysql_port
122+
to_port = local.mysql_port
123+
ip_protocol = "tcp"
126124
referenced_security_group_id = var.rds_allow_eks_sg
127125
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "mysql_host" {
22
description = "MySQL endpoint"
3-
value = aws_rds_cluster.comet-ml-cluster.endpoint
3+
value = aws_rds_cluster.cometml-db-cluster.endpoint
44
}

comet-infrastructure/modules/comet_rds/variables.tf

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,79 @@ variable "environment" {
44
default = "dev"
55
}
66

7-
variable "rds_root_password" {
8-
description = "Root password for RDS database"
7+
variable "availability_zones" {
8+
description = "List of availability zones from VPC"
9+
type = list(string)
10+
}
11+
12+
variable "vpc_id" {
13+
description = "ID of the VPC that will contain the provisioned resources"
914
type = string
1015
}
1116

12-
variable "rds_instance_type" {
13-
description = "Instance type for RDS database"
17+
variable "rds_private_subnets" {
18+
description = "IDs of private subnets within the VPC"
19+
type = list(string)
20+
}
21+
22+
variable "rds_allow_ec2_sg" {
23+
description = "Security group associated with EC2 compute, if provisioned"
1424
type = string
15-
default = "db.r5.xlarge"
1625
}
1726

18-
variable "rds_instance_count" {
19-
description = "Number of RDS instances in the database cluster"
20-
type = number
21-
default = 2
27+
variable "rds_allow_eks_sg" {
28+
description = "Security group associated with EKS compute, if provisioned"
29+
type = string
2230
}
2331

2432
variable "rds_engine" {
2533
description = "Engine type for RDS database"
2634
type = string
27-
default = "aurora-mysql"
2835
}
2936

3037
variable "rds_engine_version" {
3138
description = "Engine version number for RDS database"
3239
type = string
33-
default = "5.7.mysql_aurora.2.07.2"
3440
}
3541

36-
variable "vpc_id" {
37-
description = "ID of the VPC that will contain the provisioned resources"
42+
variable "rds_instance_type" {
43+
description = "Instance type for RDS database"
3844
type = string
39-
default = ""
4045
}
4146

42-
variable "vpc_private_subnets" {
43-
description = "IDs of private subnets within the VPC"
44-
type = list(string)
45-
default = []
47+
variable "rds_instance_count" {
48+
description = "Number of RDS instances in the database cluster"
49+
type = number
4650
}
4751

48-
variable "availability_zones" {
49-
description = "List of availability zones from VPC"
50-
type = list(string)
51-
default = []
52+
variable "rds_storage_encrypted" {
53+
description = "Enables encryption for RDS storage"
54+
type = bool
5255
}
5356

54-
variable "rds_allow_ec2_sg" {
55-
description = "Security group associated with EC2 compute, if provisioned"
57+
variable "rds_iam_db_auth" {
58+
description = "Enables IAM auth for the database in RDS"
59+
type = bool
60+
}
61+
62+
variable "rds_backup_retention_period" {
63+
description = "Days specified for RDS snapshotretention period"
64+
type = number
65+
}
66+
67+
variable "rds_preferred_backup_window" {
68+
description = "Backup window for RDS"
5669
type = string
57-
default = ""
5870
}
5971

60-
variable "rds_allow_eks_sg" {
61-
description = "Security group associated with EKS compute, if provisioned"
72+
variable "rds_database_name" {
73+
description = "Name for the application database in RDS"
74+
type = string
75+
}
76+
77+
variable "rds_root_password" {
78+
description = "Root password for RDS database"
6279
type = string
63-
default = ""
6480
}
6581

6682
variable "ec2_enabled" {

0 commit comments

Comments
 (0)