Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable specifying the AMI ID for EC2 instance #14

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "comet_ec2" {
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
comet_ec2_subnet = var.enable_vpc ? module.comet_vpc[0].public_subnets[0] : var.comet_public_subnets[0]
comet_ec2_ami_type = var.comet_ec2_ami_type
comet_ec2_ami_id = var.comet_ec2_ami_id
comet_ec2_instance_type = var.comet_ec2_instance_type
comet_ec2_instance_count = var.comet_ec2_instance_count
comet_ec2_volume_type = var.comet_ec2_volume_type
Expand Down
17 changes: 9 additions & 8 deletions modules/comet_ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ data "aws_ami" "ubuntu22" {
}

resource "aws_instance" "comet_ec2" {
ami = var.comet_ec2_ami_type == "al2" ? data.aws_ami.al2.id : (
var.comet_ec2_ami_type == "rhel7" ? data.aws_ami.rhel7.id : (
var.comet_ec2_ami_type == "rhel8" ? data.aws_ami.rhel8.id : (
var.comet_ec2_ami_type == "rhel9" ? data.aws_ami.rhel9.id : (
var.comet_ec2_ami_type == "ubuntu18" ? data.aws_ami.ubuntu18.id : (
var.comet_ec2_ami_type == "ubuntu20" ? data.aws_ami.ubuntu20.id : (
var.comet_ec2_ami_type == "ubuntu22" ? data.aws_ami.ubuntu22.id : (
null)))))))
ami = var.comet_ec2_ami_id != "" ? var.comet_ec2_ami_id : (
var.comet_ec2_ami_type == "al2" ? data.aws_ami.al2.id : (
var.comet_ec2_ami_type == "rhel7" ? data.aws_ami.rhel7.id : (
var.comet_ec2_ami_type == "rhel8" ? data.aws_ami.rhel8.id : (
var.comet_ec2_ami_type == "rhel9" ? data.aws_ami.rhel9.id : (
var.comet_ec2_ami_type == "ubuntu18" ? data.aws_ami.ubuntu18.id : (
var.comet_ec2_ami_type == "ubuntu20" ? data.aws_ami.ubuntu20.id : (
var.comet_ec2_ami_type == "ubuntu22" ? data.aws_ami.ubuntu22.id : (
null))))))))
instance_type = var.comet_ec2_instance_type
key_name = var.comet_ec2_key
count = var.comet_ec2_instance_count
Expand Down
5 changes: 5 additions & 0 deletions modules/comet_ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ variable "comet_ec2_instance_type" {
type = string
}

variable "comet_ec2_ami_id" {
description = "AMI ID for the EC2 instance"
type = string
}

variable "comet_ec2_instance_count" {
description = "Number of EC2 instances to provision"
type = number
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ variable "comet_ec2_ami_type" {
}
}

variable "comet_ec2_ami_id" {
description = "AMI ID for the EC2 instance"
type = string
default = ""
}

variable "comet_ec2_instance_type" {
description = "Instance type for the EC2 instance"
type = string
Expand Down Expand Up @@ -202,7 +208,7 @@ variable "eks_external_dns" {
variable "eks_external_dns_r53_zones" {
description = "Route 53 zones for external-dns to have access to"
type = list(string)
default = [
default = [
"arn:aws:route53:::hostedzone/XYZ"
]
}
Expand Down