Skip to content

Commit 1aedb30

Browse files
authored
Merge pull request #14 from comet-ml/ec2-ami-id
Enable specifying the AMI ID for EC2 instance
2 parents 52f7a30 + dbc95b7 commit 1aedb30

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module "comet_ec2" {
2828
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
2929
comet_ec2_subnet = var.enable_vpc ? module.comet_vpc[0].public_subnets[0] : var.comet_public_subnets[0]
3030
comet_ec2_ami_type = var.comet_ec2_ami_type
31+
comet_ec2_ami_id = var.comet_ec2_ami_id
3132
comet_ec2_instance_type = var.comet_ec2_instance_type
3233
comet_ec2_instance_count = var.comet_ec2_instance_count
3334
comet_ec2_volume_type = var.comet_ec2_volume_type

modules/comet_ec2/main.tf

+9-8
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ data "aws_ami" "ubuntu22" {
124124
}
125125

126126
resource "aws_instance" "comet_ec2" {
127-
ami = var.comet_ec2_ami_type == "al2" ? data.aws_ami.al2.id : (
128-
var.comet_ec2_ami_type == "rhel7" ? data.aws_ami.rhel7.id : (
129-
var.comet_ec2_ami_type == "rhel8" ? data.aws_ami.rhel8.id : (
130-
var.comet_ec2_ami_type == "rhel9" ? data.aws_ami.rhel9.id : (
131-
var.comet_ec2_ami_type == "ubuntu18" ? data.aws_ami.ubuntu18.id : (
132-
var.comet_ec2_ami_type == "ubuntu20" ? data.aws_ami.ubuntu20.id : (
133-
var.comet_ec2_ami_type == "ubuntu22" ? data.aws_ami.ubuntu22.id : (
134-
null)))))))
127+
ami = var.comet_ec2_ami_id != "" ? var.comet_ec2_ami_id : (
128+
var.comet_ec2_ami_type == "al2" ? data.aws_ami.al2.id : (
129+
var.comet_ec2_ami_type == "rhel7" ? data.aws_ami.rhel7.id : (
130+
var.comet_ec2_ami_type == "rhel8" ? data.aws_ami.rhel8.id : (
131+
var.comet_ec2_ami_type == "rhel9" ? data.aws_ami.rhel9.id : (
132+
var.comet_ec2_ami_type == "ubuntu18" ? data.aws_ami.ubuntu18.id : (
133+
var.comet_ec2_ami_type == "ubuntu20" ? data.aws_ami.ubuntu20.id : (
134+
var.comet_ec2_ami_type == "ubuntu22" ? data.aws_ami.ubuntu22.id : (
135+
null))))))))
135136
instance_type = var.comet_ec2_instance_type
136137
key_name = var.comet_ec2_key
137138
count = var.comet_ec2_instance_count

modules/comet_ec2/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ variable "comet_ec2_instance_type" {
3030
type = string
3131
}
3232

33+
variable "comet_ec2_ami_id" {
34+
description = "AMI ID for the EC2 instance"
35+
type = string
36+
}
37+
3338
variable "comet_ec2_instance_count" {
3439
description = "Number of EC2 instances to provision"
3540
type = number

variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ variable "comet_ec2_ami_type" {
8989
}
9090
}
9191

92+
variable "comet_ec2_ami_id" {
93+
description = "AMI ID for the EC2 instance"
94+
type = string
95+
default = ""
96+
}
97+
9298
variable "comet_ec2_instance_type" {
9399
description = "Instance type for the EC2 instance"
94100
type = string
@@ -202,7 +208,7 @@ variable "eks_external_dns" {
202208
variable "eks_external_dns_r53_zones" {
203209
description = "Route 53 zones for external-dns to have access to"
204210
type = list(string)
205-
default = [
211+
default = [
206212
"arn:aws:route53:::hostedzone/XYZ"
207213
]
208214
}

0 commit comments

Comments
 (0)