Skip to content

Commit

Permalink
feat: add IaC with Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-kumar00 committed Jan 27, 2025
1 parent 666da1d commit ea2f044
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 32 deletions.
37 changes: 37 additions & 0 deletions infrastructure/.gitignore
Original file line number Diff line number Diff line change
@@ -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
71 changes: 41 additions & 30 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -1,60 +1,71 @@
# Create a VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true

}

# create a subnet 1
resource "aws_subnet" "subnet_1" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/20"
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
}
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/20"
availability_zone = "ap-south-1a"
map_public_ip_on_launch = true
}

# create a subnet 2
resource "aws_subnet" "subnet_2" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.16.0/20"
availability_zone = "us-east-1c"
map_public_ip_on_launch = true
}
vpc_id = aws_vpc.main.id
cidr_block = "10.0.16.0/20"
availability_zone = "ap-south-1b"
map_public_ip_on_launch = true
}

# create a subnet 3
resource "aws_subnet" "subnet_3" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.32.0/20"
availability_zone = "us-east-1d"
map_public_ip_on_launch = true
}

vpc_id = aws_vpc.main.id
cidr_block = "10.0.32.0/20"
availability_zone = "ap-south-1c"
map_public_ip_on_launch = true
}

resource "aws_internet_gateway" "internet_gw" {
vpc_id = aws_vpc.main.id
vpc_id = aws_vpc.main.id
}

resource "aws_route_table" "route_table" {
vpc_id = aws_vpc.main.id

vpc_id = aws_vpc.main.id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gw.id

}

route {
cidr_block = "10.0.0.0/16"
gateway_id = "local"
}
}
}


resource "aws_route_table_association" "subnet_1_association" {
subnet_id = aws_subnet.subnet_1.id
route_table_id = aws_route_table.route_table.id
}

resource "aws_route_table_association" "subnet_2_association" {
subnet_id = aws_subnet.subnet_2.id
route_table_id = aws_route_table.route_table.id
}

resource "aws_route_table_association" "subnet_3_association" {
subnet_id = aws_subnet.subnet_3.id
route_table_id = aws_route_table.route_table.id
}

# Use of EKS Module

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.0"

cluster_name = "devops-url2qr-capstone"
cluster_name = "devops-capstone-project"
cluster_version = "1.27"

cluster_endpoint_public_access = true
Expand All @@ -66,9 +77,9 @@ module "eks" {
eks_managed_node_groups = {
green = {
min_size = 1
max_size = 1
max_size = 2
desired_size = 1
instance_types = ["t3.medium"]
}
}
}
}
6 changes: 4 additions & 2 deletions infrastructure/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ terraform {
}
}



# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}
region = "ap-south-1"
}

0 comments on commit ea2f044

Please sign in to comment.