From 43e8c262fdc4ba9f8e2983cf689d0092ffa6e422 Mon Sep 17 00:00:00 2001 From: Shubham Londhe Date: Fri, 30 Aug 2024 23:19:36 +0530 Subject: [PATCH] Add files via upload --- terraform/ec2.tf | 63 ++++++++++++++++++++++++++++++++++++++++++ terraform/variables.tf | 14 ++++++++++ 2 files changed, 77 insertions(+) create mode 100644 terraform/ec2.tf create mode 100644 terraform/variables.tf diff --git a/terraform/ec2.tf b/terraform/ec2.tf new file mode 100644 index 00000000..f2517e5e --- /dev/null +++ b/terraform/ec2.tf @@ -0,0 +1,63 @@ +resource "aws_key_pair" "deployer" { + key_name = "terra-automate-key" + public_key = file("/Users/shubham/Documents/work/TrainWithShubham/terra-practice/terra-key.pub") +} + +resource "aws_default_vpc" "default" { + +} + +resource "aws_security_group" "allow_user_to_connect" { + name = "allow TLS" + description = "Allow user to connect" + vpc_id = aws_default_vpc.default.id + ingress { + description = "port 22 allow" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + description = " allow all outgoing traffic " + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "port 80 allow" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "port 443 allow" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "mysecurity" + } +} + +resource "aws_instance" "testinstance" { + ami = var.ami_id + instance_type = var.instance_type + key_name = aws_key_pair.deployer.key_name + security_groups = [aws_security_group.allow_user_to_connect.name] + tags = { + Name = "Automate" + } + root_block_device { + volume_size = 30 + volume_type = "gp3" + } +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 00000000..09359849 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,14 @@ +variable "aws_region" { + description = "AWS region where resources will be provisioned" + default = "us-east-2" +} + +variable "ami_id" { + description = "AMI ID for the EC2 instance" + default = "ami-085f9c64a9b75eed5" +} + +variable "instance_type" { + description = "Instance type for the EC2 instance" + default = "t2.large" +}