From 6df047c3871b3492a468b1d005e6d18c7222d1cd Mon Sep 17 00:00:00 2001 From: Kshitij Date: Fri, 5 Sep 2025 01:09:01 +0530 Subject: [PATCH] Added comments for future ref. --- Terraform/main.tf | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Terraform/main.tf b/Terraform/main.tf index 6dea987..82eaaf5 100644 --- a/Terraform/main.tf +++ b/Terraform/main.tf @@ -4,32 +4,34 @@ provider "aws" { # EC2 instance resource "aws_instance" "ec2_t2-micro" { - ami = "ami-0861f4e788f5069dd" # Amazon Linux - 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.ec2_ssh_security.id] + ami = "ami-0861f4e788f5069dd" # Amazon Linux + instance_type = "t2.micro" # Instance type + key_name = "kshitij-personal-ed25519" # SSH keys + subnet_id = "subnet-0f2515644bbe8e603" # VPC -> Subnet ID + associate_public_ip_address = true # Public IP for SSH + vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id] # VPC security group tags = { - Name = "Test-EC2" + Name = "Test-EC2" # Instance name } } # Security group (firewall) for allowing incoming SSH connections resource "aws_security_group" "ec2_ssh_security" { - name = "allow_ssh" + name = "allow_ssh" # Firewall rule name ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["${var.ssh_ingress}"] + # Ingress rules (incoming) + from_port = 22 # Starting port range + to_port = 22 # End port range + protocol = "tcp" # Allowed protocol + cidr_blocks = ["${var.ssh_ingress}"] # Allowed IP ranges } egress { - from_port = 0 - to_port = 0 - protocol = -1 - cidr_blocks = ["0.0.0.0/0"] + from_port = 0 # Starting port range; 0 implies all ports + to_port = 0 # End port range; 0 implies all ports + protocol = -1 # Allowed protocol; -1 implies all protocols (in HCL) + cidr_blocks = ["0.0.0.0/0"] # Allowed IP ranges } + # For each protocol, new block; eg. egress { from... to... protocol = "icmp" cidr...} }