From 8387d516a33a55d2dcb680930594b8ce65f87d48 Mon Sep 17 00:00:00 2001 From: TheMannu Date: Tue, 6 Aug 2024 17:56:51 +0530 Subject: [PATCH] Created Tf files for EC2, IAM, S3, VPC, SG and provider.tf --- .gitignore | 37 +++++++++++++++++++++++++ Create-EC2-Instance/main.tf | 8 ++++++ Create-IAM-User/main.tf | 11 ++++++++ Create-S3-Bucket/main.tf | 3 ++ Create-Security-Group/main.tf | 37 +++++++++++++++++++++++++ Create-VPC/main.tf | 52 +++++++++++++++++++++++++++++++++++ provider.tf | 12 ++++++++ 7 files changed, 160 insertions(+) create mode 100644 .gitignore create mode 100644 Create-EC2-Instance/main.tf create mode 100644 Create-IAM-User/main.tf create mode 100644 Create-S3-Bucket/main.tf create mode 100644 Create-Security-Group/main.tf create mode 100644 Create-VPC/main.tf create mode 100644 provider.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21e6d3c --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore transient lock info files created by terraform apply +.terraform.tfstate.lock.info + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc \ No newline at end of file diff --git a/Create-EC2-Instance/main.tf b/Create-EC2-Instance/main.tf new file mode 100644 index 0000000..07a7086 --- /dev/null +++ b/Create-EC2-Instance/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "ec2-instance" { + ami = "ami-04a81a99f5ec58529" + instance_type = "t2.micro" + + tags = { + Name = "ashwan-isntance" + } +} \ No newline at end of file diff --git a/Create-IAM-User/main.tf b/Create-IAM-User/main.tf new file mode 100644 index 0000000..d07a490 --- /dev/null +++ b/Create-IAM-User/main.tf @@ -0,0 +1,11 @@ + +resource "aws_iam_user" "ashwan-user" { + name = "ashwan-cloud-user" + path = "/" +} + +resource "aws_iam_access_key" "user_access_key" { + user = aws_iam_user.ashwan-user.name +} + + diff --git a/Create-S3-Bucket/main.tf b/Create-S3-Bucket/main.tf new file mode 100644 index 0000000..78e13ec --- /dev/null +++ b/Create-S3-Bucket/main.tf @@ -0,0 +1,3 @@ +resource "aws_s3_bucket" "s3-bucket" { + bucket = "ashwan-bucket-terraform-cloudHub8877" +} \ No newline at end of file diff --git a/Create-Security-Group/main.tf b/Create-Security-Group/main.tf new file mode 100644 index 0000000..885d0c5 --- /dev/null +++ b/Create-Security-Group/main.tf @@ -0,0 +1,37 @@ + +resource "aws_security_group" "ashwan_sg" { + name = "ashwan-sg" + description = "Security group with ports 22, 80, and 443 open" + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "ashwan-sg" + } +} diff --git a/Create-VPC/main.tf b/Create-VPC/main.tf new file mode 100644 index 0000000..efc7789 --- /dev/null +++ b/Create-VPC/main.tf @@ -0,0 +1,52 @@ +# Create a VPC +resource "aws_vpc" "ashwan-vpc" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = "ashwan-vpc" + } +} + +# Creating private subnet +resource "aws_subnet" "private-subnet" { + cidr_block = "10.0.1.0/24" + vpc_id = aws_vpc.ashwan-vpc.id + + tags = { + Name = "private-subnet" + } +} + +# Creating public subnet +resource "aws_subnet" "public-subnet" { + cidr_block = "10.0.2.0/24" + vpc_id = aws_vpc.ashwan-vpc.id + + tags = { + Name = "public-subnet" + } +} + +# Internet Gateway +resource "aws_internet_gateway" "ashwan-igw" { + vpc_id = aws_vpc.ashwan-vpc.id + + tags = { + Name = "ashwan-igw" + } +} + +# Routing table +resource "aws_route_table" "ashwan-rt" { + vpc_id =aws_vpc.ashwan-vpc.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.ashwan-igw.id + } +} + +resource "aws_route_table_association" "public-sub" { + route_table_id = aws_route_table.ashwan-rt.id + subnet_id = aws_subnet.public-subnet.id +} \ No newline at end of file diff --git a/provider.tf b/provider.tf new file mode 100644 index 0000000..4734058 --- /dev/null +++ b/provider.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "5.61.0" + } + } +} + +provider "aws" { + region = "ap-south-1" +} \ No newline at end of file