From aad9d5cfe8e4ad52636caeb62368149a06f6c45f Mon Sep 17 00:00:00 2001 From: Syuqri Date: Sun, 10 Dec 2023 15:06:56 +0800 Subject: [PATCH] Add second EC2 instance --- main.tf | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.tf b/main.tf index 3c10d93..8c7e911 100644 --- a/main.tf +++ b/main.tf @@ -65,3 +65,31 @@ resource "aws_instance" "first" { Name = "first_instance" } } + +resource "aws_security_group" "second_instance_sg" { + name = "second_instance_sg" + vpc_id = aws_vpc.main.id + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "second_instance_sg" + } +} + +resource "aws_instance" "second" { + ami = data.aws_ami.aml2.id + instance_type = "t3.micro" + subnet_id = aws_subnet.second.id + vpc_security_group_ids = [aws_security_group.second_instance_sg.id] + iam_instance_profile = aws_iam_instance_profile.ec2_instance_profile.name + + tags = { + Name = "second_instance" + } +}