Skip to content

Commit

Permalink
Update main.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadll authored Feb 2, 2024
1 parent 9f12501 commit 9bd3eff
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion modules/EC2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ locals {
create_network_interface = var.create_network_interface
}

data "aws_ami" "amazon-linux" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["al2023-ami-2023*kernel-6.1-x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

resource "aws_key_pair" "ec2" {
count = local.create_instace ? 1 : 0
key_name = "ec2-instance"
Expand Down Expand Up @@ -42,7 +62,7 @@ resource "aws_placement_group" "partition" {

resource "aws_instance" "terraform" {
count = local.create_instace ? 1 : 0
ami = var.ami_id
ami = data.aws_ami.amazon-linux.id
instance_type = var.instance_type
placement_group = local.create_placement_group ? aws_placement_group.partition[0].id : null
key_name = aws_key_pair.ec2[0].key_name
Expand Down

0 comments on commit 9bd3eff

Please sign in to comment.