Skip to content

Commit 31a4817

Browse files
committed
expose all vars from comet_ec2 into root
1 parent a1f8e0e commit 31a4817

File tree

4 files changed

+101
-63
lines changed

4 files changed

+101
-63
lines changed

comet-infrastructure/main.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,32 @@ 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
56+
vpc_id = module.vpc.vpc_id
5957
comet_ec2_subnet = module.vpc.public_subnets[count.index % length(module.vpc.public_subnets)]
6058

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
59+
comet_ec2_ami = var.comet_ec2_ami
60+
comet_ec2_instance_type = var.comet_ec2_instance_type
61+
comet_ec2_instance_count = var.comet_ec2_instance_count
62+
comet_ec2_volume_type = var.comet_ec2_volume_type
63+
comet_ec2_volume_size = var.comet_ec2_volume_size
64+
comet_ec2_key = var.comet_ec2_key
6465

6566
alb_enabled = var.enable_ec2_alb
67+
68+
s3_enabled = var.enable_s3
69+
comet_ml_s3_bucket = var.s3_bucket_name
70+
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null
6671
}
6772

6873
module "comet_ec2_alb" {

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" {

comet-infrastructure/variables.tf

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
#global
12
variable "environment" {
23
description = "Deployment environment, i.e. dev/stage/prod, etc"
34
type = string
45
default = "dev"
56
}
67

8+
variable "region" {
9+
description = "AWS region to provision resources in"
10+
type = string
11+
}
12+
13+
#child module toggles
714
variable "enable_ec2" {
815
description = "Toggles the EC2 module, to provision EC2 resources for running Comet"
916
type = bool
@@ -34,9 +41,11 @@ variable "enable_s3" {
3441
type = bool
3542
}
3643

37-
variable "region" {
38-
description = "AWS region to provision resources in"
44+
#comet_ec2
45+
variable "comet_ec2_subnet" {
46+
description = "ID of VPC subnet to launch EC2 instance in"
3947
type = string
48+
default = null
4049
}
4150

4251
variable "comet_ec2_ami" {
@@ -45,21 +54,48 @@ variable "comet_ec2_ami" {
4554
default = "ami-05842f1afbf311a43"
4655
}
4756

48-
variable "s3_bucket_name" {
49-
description = "Name for S3 bucket"
57+
variable "comet_ec2_instance_type" {
58+
description = "Instance type for the EC2 instance"
5059
type = string
51-
default = ""
60+
default = "m5.4xlarge"
5261
}
5362

54-
variable "rds_root_password" {
55-
description = "Root password for RDS database"
63+
variable "comet_ec2_instance_count" {
64+
description = "Number of EC2 instances to provision"
65+
type = number
66+
default = 1
67+
}
68+
69+
variable "comet_ec2_volume_type" {
70+
description = "EBS volume type for the EC2 instance root volume"
71+
type = string
72+
default = "gp2"
73+
}
74+
75+
variable "comet_ec2_volume_size" {
76+
description = "Size, in gibibytes (GiB), for the EC2 instance root volume"
77+
type = number
78+
default = 1024
79+
}
80+
81+
variable "comet_ec2_key" {
82+
description = "Name of the SSH key to configure on the EC2 instance"
5683
type = string
84+
default = null
5785
}
5886

87+
#comet_ec2_alb
88+
variable "ssl_certificate_arn" {
89+
description = "ARN of the ACM certificate to use for the ALB"
90+
type = string
91+
default = ""
92+
}
93+
94+
#comet_eks
5995
variable "eks_cluster_name" {
6096
description = "Name for EKS cluster"
6197
type = string
62-
default = "cometeks"
98+
default = "comet-eks"
6399
}
64100

65101
variable "eks_cluster_version" {
@@ -68,8 +104,14 @@ variable "eks_cluster_version" {
68104
default = "1.26"
69105
}
70106

71-
variable "ssl_certificate_arn" {
72-
description = "ARN of the ACM certificate to use for the ALB"
107+
# comet_rds
108+
variable "rds_root_password" {
109+
description = "Root password for RDS database"
110+
type = string
111+
}
112+
113+
variable "s3_bucket_name" {
114+
description = "Name for S3 bucket"
73115
type = string
74116
default = ""
75117
}

0 commit comments

Comments
 (0)