From fd60ab84c27cf280020346e35e9a87aca59ba0e1 Mon Sep 17 00:00:00 2001 From: geezo Date: Tue, 25 Feb 2025 02:41:37 +0000 Subject: [PATCH] Create tf --- main.tf | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main.tf diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e710a8e --- /dev/null +++ b/main.tf @@ -0,0 +1,38 @@ +provider "aws" { + region = "us-east-1" # Change this to your preferred region +} + +resource "aws_security_group" "ec2_sg" { + name = "ec2-security-group" + description = "Allow SSH inbound traffic" + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] # Open to all, restrict this for security + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_instance" "ec2_vm" { + ami = "ami-0c55b159cbfafe1f0" # Replace with a valid AMI ID for your region + instance_type = "t2.micro" # Free tier eligible instance type + security_groups = [aws_security_group.ec2_sg.name] + key_name = "your-key-pair" # Replace with your AWS key pair name + + tags = { + Name = "Terraform-EC2" + } +} + +output "instance_public_ip" { + description = "Public IP of the EC2 instance" + value = aws_instance.ec2_vm.public_ip +}