Added hcl files for terraform ec2 launched on aws. w/ ec2+security group

This commit is contained in:
K
2025-09-05 00:55:09 +05:30
parent 3350953946
commit 7310c7e1bc
2 changed files with 42 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
provider "aws" {
region = "ap-south-1"
}
resource "aws_instance" "terra-ec2" {
ami = "ami-0861f4e788f5069dd"
instance_type = "t2.micro"
key_name = "kshitij-personal-ed25519"
subnet_id = "subnet-0f2515644bbe8e603"
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.allow_ssh_terra-ec2.id]
tags = {
name = "terra-ec2"
}
}
resource "aws_security_group" "allow_ssh_terra-ec2" {
name = "allow_ssh_terra-ec2"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.internal_ip}", "${var.personal_ip}"]
}
egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
}