From 792f981f738766e9fbf31a56cd52438ab592757f Mon Sep 17 00:00:00 2001 From: VIVESH <35293085+574n13y@users.noreply.github.com> Date: Thu, 30 Nov 2023 01:35:29 +0530 Subject: [PATCH] Create main.tf --- main.tf | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 main.tf diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..ecd836b --- /dev/null +++ b/main.tf @@ -0,0 +1,61 @@ +resource "aws_instance" "ec2" { + ami = var.ami_id + instance_type = var.instance_type + key_name = var.key_name + vpc_security_group_ids = [aws_security_group.ec2_security_group.id] + user_data = base64encode(file("website.sh")) + tags = { + Name = "Aj-EC2" + } +} + +resource "aws_security_group" "ec2_security_group" { + name = "ec2 security group" + description = "allow access on ports 80 and 22 and 443" + + ingress { + description = "ssh access" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + ingress { + from_port = 0 + to_port = 0 # Allow all ports + protocol = "-1" # All protocols + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "https" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + ingress { + description = "http" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + } + + tags = { + Name = "ss_js" + } +}