Added comments for future ref.

This commit is contained in:
K
2025-09-05 01:09:01 +05:30
parent 7310c7e1bc
commit 6df047c387
+17 -15
View File
@@ -5,31 +5,33 @@ provider "aws" {
# EC2 instance # EC2 instance
resource "aws_instance" "ec2_t2-micro" { resource "aws_instance" "ec2_t2-micro" {
ami = "ami-0861f4e788f5069dd" # Amazon Linux ami = "ami-0861f4e788f5069dd" # Amazon Linux
instance_type = "t2.micro" instance_type = "t2.micro" # Instance type
key_name = "kshitij-personal-ed25519" key_name = "kshitij-personal-ed25519" # SSH keys
subnet_id = "subnet-0f2515644bbe8e603" subnet_id = "subnet-0f2515644bbe8e603" # VPC -> Subnet ID
associate_public_ip_address = true associate_public_ip_address = true # Public IP for SSH
vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id] vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id] # VPC security group
tags = { tags = {
Name = "Test-EC2" Name = "Test-EC2" # Instance name
} }
} }
# Security group (firewall) for allowing incoming SSH connections # Security group (firewall) for allowing incoming SSH connections
resource "aws_security_group" "ec2_ssh_security" { resource "aws_security_group" "ec2_ssh_security" {
name = "allow_ssh" name = "allow_ssh" # Firewall rule name
ingress { ingress {
from_port = 22 # Ingress rules (incoming)
to_port = 22 from_port = 22 # Starting port range
protocol = "tcp" to_port = 22 # End port range
cidr_blocks = ["${var.ssh_ingress}"] protocol = "tcp" # Allowed protocol
cidr_blocks = ["${var.ssh_ingress}"] # Allowed IP ranges
} }
egress { egress {
from_port = 0 from_port = 0 # Starting port range; 0 implies all ports
to_port = 0 to_port = 0 # End port range; 0 implies all ports
protocol = -1 protocol = -1 # Allowed protocol; -1 implies all protocols (in HCL)
cidr_blocks = ["0.0.0.0/0"] cidr_blocks = ["0.0.0.0/0"] # Allowed IP ranges
} }
# For each protocol, new block; eg. egress { from... to... protocol = "icmp" cidr...}
} }