Skip to content

Commit

Permalink
updated instance creation to use count meta-arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremycook123 committed Apr 25, 2024
1 parent f2e06e4 commit 0a1ff9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
29 changes: 4 additions & 25 deletions terraform/lab.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ resource "aws_iam_instance_profile" "instance" {
role = "ec2-labinstance-role"
}

resource "aws_instance" "instance_1" {
resource "aws_instance" "instances" {
count = length(local.azs)
ami = "ami-035bf26fb18e75d1b"
instance_type = "t3.micro"
key_name = data.aws_key_pair.lab.key_name
vpc_security_group_ids = [aws_security_group.instance_sg.id]
subnet_id = module.vpc.public_subnets[0]
subnet_id = element(module.vpc.public_subnets.*.id, count.index)
iam_instance_profile = aws_iam_instance_profile.instance.name
associate_public_ip_address = true

Expand All @@ -146,29 +147,7 @@ resource "aws_instance" "instance_1" {
}

tags = {
"Name" = "instance_01"
}

depends_on = [
aws_efs_mount_target.efs_mount_target
]
}

resource "aws_instance" "instance_2" {
ami = "ami-035bf26fb18e75d1b"
instance_type = "t3.micro"
key_name = data.aws_key_pair.lab.key_name
vpc_security_group_ids = [aws_security_group.instance_sg.id]
subnet_id = module.vpc.public_subnets[1]
iam_instance_profile = aws_iam_instance_profile.instance.name
associate_public_ip_address = true

credit_specification {
cpu_credits = "standard"
}

tags = {
"Name" = "instance_02"
"Name" = "instance_0${count.index + 1}"
}

depends_on = [
Expand Down
8 changes: 0 additions & 8 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ output "efs_filesystem_id" {
output "efs_filesystem_fqdn" {
value = module.efs.file_system_fqdn
}

output "instance1_public_ip" {
value = aws_instance.instance_1.public_ip
}

output "instance2_public_ip" {
value = aws_instance.instance_2.public_ip
}

0 comments on commit 0a1ff9c

Please sign in to comment.