Skip to content

Commit 31aee62

Browse files
authored
Merge pull request #1 from comet-ml/expose-vars
Expose vars
2 parents 3faf7ec + f807a2c commit 31aee62

File tree

12 files changed

+509
-255
lines changed

12 files changed

+509
-255
lines changed

comet-infrastructure/main.tf

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,97 +42,113 @@ module "vpc" {
4242
default_security_group_tags = { Name = "${local.resource_name}-default" }
4343

4444
# if EKS deployment, set subnet tags for AWS Load Balancer Controller auto-discovery
45-
public_subnet_tags = var.enable_eks ? {"kubernetes.io/role/elb" = 1} : null
45+
public_subnet_tags = var.enable_eks ? {"kubernetes.io/role/elb" = 1} : null
4646
private_subnet_tags = var.enable_eks ? {"kubernetes.io/role/internal-elb" = 1} : null
4747

4848
tags = local.tags
4949
}
5050

5151
module "comet_ec2" {
52-
source = "./modules/comet_ec2"
53-
count = var.enable_ec2 ? 1 : 0
54-
52+
source = "./modules/comet_ec2"
53+
count = var.enable_ec2 ? 1 : 0
5554
environment = var.environment
5655

57-
vpc_id = module.vpc.vpc_id
58-
comet_ec2_ami = var.comet_ec2_ami
59-
comet_ec2_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
60-
61-
s3_enabled = var.enable_s3
62-
comet_ml_s3_bucket = var.s3_bucket_name
63-
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null
56+
vpc_id = module.vpc.vpc_id
57+
comet_ec2_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
58+
comet_ec2_ami = var.comet_ec2_ami
59+
comet_ec2_instance_type = var.comet_ec2_instance_type
60+
comet_ec2_instance_count = var.comet_ec2_instance_count
61+
comet_ec2_volume_type = var.comet_ec2_volume_type
62+
comet_ec2_volume_size = var.comet_ec2_volume_size
63+
comet_ec2_key = var.comet_ec2_key
6464

6565
alb_enabled = var.enable_ec2_alb
66+
67+
s3_enabled = var.enable_s3
68+
comet_ml_s3_bucket = var.s3_bucket_name
69+
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null
6670
}
6771

6872
module "comet_ec2_alb" {
69-
source = "./modules/comet_ec2_alb"
70-
count = var.enable_ec2_alb ? 1 : 0
71-
73+
source = "./modules/comet_ec2_alb"
74+
count = var.enable_ec2_alb ? 1 : 0
7275
environment = var.environment
7376

74-
vpc_id = module.vpc.vpc_id
75-
public_subnets = module.vpc.public_subnets
76-
77+
vpc_id = module.vpc.vpc_id
78+
public_subnets = module.vpc.public_subnets
7779
ssl_certificate_arn = var.enable_ec2_alb ? var.ssl_certificate_arn : null
7880
}
7981

8082
module "comet_eks" {
81-
source = "./modules/comet_eks"
82-
count = var.enable_eks ? 1 : 0
83-
83+
source = "./modules/comet_eks"
84+
count = var.enable_eks ? 1 : 0
8485
environment = var.environment
8586

86-
vpc_id = module.vpc.vpc_id
87-
vpc_private_subnets = module.vpc.private_subnets
88-
cluster_name = var.eks_cluster_name
89-
cluster_version = var.eks_cluster_version
90-
91-
s3_enabled = var.enable_s3
87+
vpc_id = module.vpc.vpc_id
88+
eks_private_subnets = module.vpc.private_subnets
89+
eks_cluster_name = var.eks_cluster_name
90+
eks_cluster_version = var.eks_cluster_version
91+
eks_mng_name = var.eks_mng_name
92+
eks_mng_ami_type = var.eks_mng_ami_type
93+
eks_node_types = var.eks_node_types
94+
eks_mng_desired_size = var.eks_mng_desired_size
95+
eks_mng_max_size = var.eks_mng_max_size
96+
eks_aws_load_balancer_controller = var.eks_aws_load_balancer_controller
97+
eks_cert_manager = var.eks_cert_manager
98+
eks_aws_cloudwatch_metrics = var.eks_aws_cloudwatch_metrics
99+
eks_external_dns = var.eks_external_dns
100+
101+
s3_enabled = var.enable_s3
92102
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null
93103
}
94104

95105
module "comet_elasticache" {
96-
source = "./modules/comet_elasticache"
97-
count = var.enable_elasticache ? 1 : 0
98-
106+
source = "./modules/comet_elasticache"
107+
count = var.enable_elasticache ? 1 : 0
99108
environment = var.environment
100109

101110
ec2_enabled = var.enable_ec2
102111
eks_enabled = var.enable_eks
103112

104-
vpc_id = module.vpc.vpc_id
105-
vpc_private_subnets = module.vpc.private_subnets
106-
107-
# index is used on the module refs 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"
108-
elasticache_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
109-
elasticache_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
113+
vpc_id = module.vpc.vpc_id
114+
elasticache_private_subnets = module.vpc.private_subnets
115+
elasticache_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
116+
elasticache_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
117+
elasticache_engine = var.elasticache_engine
118+
elasticache_engine_version = var.elasticache_engine_version
119+
elasticache_instance_type = var.elasticache_instance_type
120+
elasticache_param_group_name = var.elasticache_param_group_name
121+
elasticache_num_cache_nodes = var.elasticache_num_cache_nodes
110122
}
111123

112124
module "comet_rds" {
113-
source = "./modules/comet_rds"
114-
count = var.enable_rds ? 1 : 0
115-
125+
source = "./modules/comet_rds"
126+
count = var.enable_rds ? 1 : 0
116127
environment = var.environment
117128

118129
ec2_enabled = var.enable_ec2
119130
eks_enabled = var.enable_eks
120131

121-
availability_zones = local.azs
122-
vpc_id = module.vpc.vpc_id
123-
vpc_private_subnets = module.vpc.private_subnets
124-
125-
# index is used on the module refs 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"
126-
rds_allow_ec2_sg = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_sg_id : null
127-
rds_allow_eks_sg = var.enable_eks ? module.comet_eks[0].nodegroup_sg_id : null
128-
129-
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
130147
}
131148

132149
module "comet_s3" {
133-
source = "./modules/comet_s3"
134-
count = var.enable_s3 ? 1 : 0
135-
150+
source = "./modules/comet_s3"
151+
count = var.enable_s3 ? 1 : 0
136152
environment = var.environment
137153

138154
comet_s3_bucket = var.s3_bucket_name

comet-infrastructure/modules/comet_ec2/main.tf

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ locals {
66
cidr_anywhere = "0.0.0.0/0"
77

88
tags = {
9-
Terraform = "true"
10-
Environment = var.environment
9+
Terraform = "true"
10+
Environment = var.environment
1111
}
1212
}
1313

1414
resource "aws_instance" "comet_ec2" {
15-
ami = var.comet_ec2_ami
16-
instance_type = var.comet_ec2_instance_type
17-
key_name = var.key_name
18-
count = var.comet_ec2_instance_count
19-
iam_instance_profile = aws_iam_instance_profile.comet-ec2-instance-profile.name
20-
subnet_id = var.comet_ec2_subnet
15+
ami = var.comet_ec2_ami
16+
instance_type = var.comet_ec2_instance_type
17+
key_name = var.comet_ec2_key
18+
count = var.comet_ec2_instance_count
19+
iam_instance_profile = aws_iam_instance_profile.comet-ec2-instance-profile.name
20+
subnet_id = var.comet_ec2_subnet
2121
vpc_security_group_ids = [aws_security_group.comet_ec2_sg.id]
2222

2323
#associate_public_ip_address = true
@@ -36,9 +36,8 @@ resource "aws_instance" "comet_ec2" {
3636
}
3737
}
3838

39-
# need to make this conditional based on ALB usage
4039
resource "aws_eip" "comet_ec2_eip" {
41-
count = var.alb_enabled ? 0 : 1
40+
count = var.alb_enabled ? 0 : 1
4241
instance = aws_instance.comet_ec2[0].id
4342
domain = "vpc"
4443
}
@@ -52,31 +51,31 @@ resource "aws_security_group" "comet_ec2_sg" {
5251
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_ssh" {
5352
security_group_id = aws_security_group.comet_ec2_sg.id
5453

55-
from_port = local.ssh_port
56-
to_port = local.ssh_port
54+
from_port = local.ssh_port
55+
to_port = local.ssh_port
5756
ip_protocol = "tcp"
5857
# make more restrictive
59-
cidr_ipv4 = local.cidr_anywhere
58+
cidr_ipv4 = local.cidr_anywhere
6059
}
6160

6261
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_http" {
6362
security_group_id = aws_security_group.comet_ec2_sg.id
6463

65-
from_port = local.http_port
66-
to_port = local.http_port
64+
from_port = local.http_port
65+
to_port = local.http_port
6766
ip_protocol = "tcp"
6867
# make more restrictive
69-
cidr_ipv4 = local.cidr_anywhere
68+
cidr_ipv4 = local.cidr_anywhere
7069
}
7170

7271
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_https" {
7372
security_group_id = aws_security_group.comet_ec2_sg.id
7473

75-
from_port = local.https_port
76-
to_port = local.https_port
74+
from_port = local.https_port
75+
to_port = local.https_port
7776
ip_protocol = "tcp"
7877
# make more restrictive
79-
cidr_ipv4 = local.cidr_anywhere
78+
cidr_ipv4 = local.cidr_anywhere
8079
}
8180

8281
/*
@@ -92,8 +91,8 @@ resource "aws_vpc_security_group_ingress_rule" "comet_ec2_alb_http" {
9291

9392
resource "aws_vpc_security_group_egress_rule" "comet_ec2_egress_any" {
9493
security_group_id = aws_security_group.comet_ec2_sg.id
95-
ip_protocol = "-1"
96-
cidr_ipv4 = local.cidr_anywhere
94+
ip_protocol = "-1"
95+
cidr_ipv4 = local.cidr_anywhere
9796
}
9897

9998
resource "aws_iam_role" "comet-ec2-s3-access-role" {

comet-infrastructure/modules/comet_ec2/variables.tf

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,56 @@ variable "environment" {
44
default = "dev"
55
}
66

7+
variable "alb_enabled" {
8+
description = "Indicates if ALB is being provisioned for Comet EC2 instance"
9+
type = bool
10+
default = null
11+
}
12+
13+
variable "s3_enabled" {
14+
description = "Indicates if S3 bucket is being provisioned for Comet"
15+
type = bool
16+
default = null
17+
}
18+
719
variable "vpc_id" {
820
description = "ID of the VPC that will contain the provisioned resources"
921
type = string
10-
#default = ""
1122
}
1223

1324
variable "comet_ec2_ami" {
1425
description = "AMI for the EC2 instance"
1526
type = string
16-
default = ""
1727
}
1828

1929
variable "comet_ec2_instance_type" {
2030
description = "Instance type for the EC2 instance"
2131
type = string
22-
default = "m5.4xlarge"
23-
}
24-
25-
variable "key_name" {
26-
description = "Name of the SSH key to configure on the EC2 instance"
27-
type = string
28-
default = ""
2932
}
3033

3134
variable "comet_ec2_instance_count" {
3235
description = "Number of EC2 instances to provision"
3336
type = number
34-
default = 1
3537
}
3638

3739
variable "comet_ec2_volume_type" {
3840
description = "EBS volume type for the EC2 instance root volume"
3941
type = string
40-
default = "gp2"
4142
}
4243

4344
variable "comet_ec2_volume_size" {
4445
description = "Size, in gibibytes (GiB), for the EC2 instance root volume"
4546
type = number
46-
default = 1024
4747
}
4848

4949
variable "comet_ec2_subnet" {
5050
description = "ID of VPC subnet to launch EC2 instance in"
5151
type = string
52-
default = ""
53-
}
54-
55-
variable "s3_enabled" {
56-
description = "Indicates if S3 bucket is being provisioned for Comet"
57-
type = bool
58-
default = null
5952
}
6053

61-
variable "alb_enabled" {
62-
description = "Indicates if ALB is being provisioned for Comet EC2 instance"
63-
type = bool
64-
default = null
54+
variable "comet_ec2_key" {
55+
description = "Name of the SSH key to configure on the EC2 instance"
56+
type = string
6557
}
6658

6759
variable "comet_ml_s3_bucket" {

0 commit comments

Comments
 (0)