Added comments for future ref.

This commit is contained in:
K
2025-09-05 01:09:01 +05:30
parent 7310c7e1bc
commit 6df047c387
+18 -16
View File
@@ -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...}
}