From 7310c7e1bc98796222a9d466807fbe40ba385dda Mon Sep 17 00:00:00 2001 From: Kshitij Date: Fri, 5 Sep 2025 00:55:09 +0530 Subject: [PATCH] Added hcl files for terraform ec2 launched on aws. w/ ec2+security group --- Terraform/terra-ec2/main.tf | 33 ++++++++++++++++++++++++++++++++ Terraform/terra-ec2/variables.tf | 9 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 Terraform/terra-ec2/main.tf create mode 100644 Terraform/terra-ec2/variables.tf diff --git a/Terraform/terra-ec2/main.tf b/Terraform/terra-ec2/main.tf new file mode 100644 index 0000000..925e3fa --- /dev/null +++ b/Terraform/terra-ec2/main.tf @@ -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"] + } +} diff --git a/Terraform/terra-ec2/variables.tf b/Terraform/terra-ec2/variables.tf new file mode 100644 index 0000000..bf216ee --- /dev/null +++ b/Terraform/terra-ec2/variables.tf @@ -0,0 +1,9 @@ +variable "internal_ip" { + description = "Internal IP allowing SSH access to terra-ec2" + type = string +} + +variable "personal_ip" { + description = "Personal IP allowing SSH access to terra-ec2" + type = string +}