Skip to content

Commit e54e40a

Browse files
committed
Add outputs that are required or helpful post-provisioning
1 parent d6a2c43 commit e54e40a

File tree

11 files changed

+1598
-4
lines changed

11 files changed

+1598
-4
lines changed

comet-infrastructure/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ module "comet_ec2" {
6161
s3_enabled = var.enable_s3
6262
comet_ml_s3_bucket = var.s3_bucket_name
6363
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null
64+
65+
alb_enabled = var.enable_ec2_alb
6466
}
6567

6668
module "comet_ec2_alb" {

comet-infrastructure/modules/comet_ec2/main.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
locals {
22
ssh_port = 22
33
http_port = 80
4+
https_port = 443
45
any_port = 0
56
cidr_anywhere = "0.0.0.0/0"
67

@@ -18,7 +19,8 @@ resource "aws_instance" "comet_ec2" {
1819
iam_instance_profile = aws_iam_instance_profile.comet-ec2-instance-profile.name
1920
subnet_id = var.comet_ec2_subnet
2021
vpc_security_group_ids = [aws_security_group.comet_ec2_sg.id]
21-
associate_public_ip_address = true
22+
23+
#associate_public_ip_address = true
2224

2325
root_block_device {
2426
volume_type = var.comet_ec2_volume_type
@@ -34,6 +36,13 @@ resource "aws_instance" "comet_ec2" {
3436
}
3537
}
3638

39+
# need to make this conditional based on ALB usage
40+
resource "aws_eip" "comet_ec2_eip" {
41+
count = var.alb_enabled ? 0 : 1
42+
instance = aws_instance.comet_ec2[0].id
43+
domain = "vpc"
44+
}
45+
3746
resource "aws_security_group" "comet_ec2_sg" {
3847
name = "comet_${var.environment}_ec2_sg"
3948
description = "Comet EC2 instance security group"
@@ -60,6 +69,16 @@ resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_http" {
6069
cidr_ipv4 = local.cidr_anywhere
6170
}
6271

72+
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_ingress_https" {
73+
security_group_id = aws_security_group.comet_ec2_sg.id
74+
75+
from_port = local.https_port
76+
to_port = local.https_port
77+
ip_protocol = "tcp"
78+
# make more restrictive
79+
cidr_ipv4 = local.cidr_anywhere
80+
}
81+
6382
/*
6483
resource "aws_vpc_security_group_ingress_rule" "comet_ec2_alb_http" {
6584
security_group_id = aws_security_group.comet_ec2_sg.id
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
output "comet_ec2_sg_id" {
2+
description = "ID of the security group associated with the EC2 instance"
23
value = aws_security_group.comet_ec2_sg.id
3-
description = "ID of the security group associated with the comet_ec2 instance"
4+
}
5+
6+
output "comet_ec2_instance_id" {
7+
description = "ID of the EC2 instance"
8+
value = aws_instance.comet_ec2[0].id
9+
}
10+
11+
output "comet_ec2_public_ip" {
12+
description = "Public IP of the EIP associated with the EC2 instance"
13+
value = var.alb_enabled ? null : aws_eip.comet_ec2_eip[0].public_ip
414
}

comet-infrastructure/modules/comet_ec2/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ variable "s3_enabled" {
5858
default = null
5959
}
6060

61+
variable "alb_enabled" {
62+
description = "Indicates if ALB is being provisioned for Comet EC2 instance"
63+
type = bool
64+
default = null
65+
}
66+
6167
variable "comet_ml_s3_bucket" {
6268
description = "Name of the S3 bucket provisioned for Comet"
6369
type = string
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "alb_dns_name" {
2+
description = "DNS name of the ALB"
3+
value = module.alb.lb_dns_name
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* only available for Memcached cluster
2+
output "redis_host" {
3+
description = "Endpoint for the ElastiCache Redis cluster"
4+
value =
5+
}
6+
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "mysql_host" {
2+
description = "MySQL endpoint"
3+
value = aws_rds_cluster.comet-ml-cluster.endpoint
4+
}

comet-infrastructure/outputs.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
output "region" {
2+
description = "Region resources are provisioned in"
3+
value = var.region
4+
}
5+
6+
output "comet_ec2_instance" {
7+
description = "ID of the Comet EC2 instance"
8+
value = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_instance_id : null
9+
}
10+
11+
output "comet_ec2_public_ip" {
12+
description = "EIP associated with the Comet EC2 instance"
13+
value = var.enable_ec2 ? module.comet_ec2[0].comet_ec2_public_ip : null
14+
}
15+
16+
output "comet_alb_dns_name" {
17+
description = "DNS name of the ALB fronting the Comet EC2 instance"
18+
value = var.enable_ec2_alb ? module.comet_ec2_alb[0].alb_dns_name : null
19+
}
20+
21+
output "mysql_host" {
22+
description = "Endpoint for the RDS instance"
23+
value = var.enable_rds ? module.comet_rds[0].mysql_host : null
24+
}
25+
126
output "configure_kubectl" {
227
description = "Configure kubectl: run the following command to update your kubeconfig with the newly provisioned cluster."
328
value = var.enable_eks ? "aws eks update-kubeconfig --region ${var.region} --name ${module.comet_eks[0].cluster_name}" : null
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "1.4.6",
4+
"serial": 71,
5+
"lineage": "0aeaf72f-38d5-19e3-b471-755a981a6d48",
6+
"outputs": {},
7+
"resources": [],
8+
"check_results": null
9+
}

0 commit comments

Comments
 (0)