Skip to content
1 change: 1 addition & 0 deletions aws/terraform-module-eks-cluster/modules/eks/reame.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# modules eks cluster
22 changes: 22 additions & 0 deletions aws/terraform-module-eks-cluster/modules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.80"
}
}
}

provider "aws" {
region = var.aws_region
}

module "vpc" {
source = "./modules/vpc"

vpc_cidr = var.vpc_cidr
availability_zones = var.availability_zones
environment = var.environment
# tag {
# }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Internet Gateway
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id

tags = {
Name = "${var.environment}-igw"
Environment = var.environment
}
}
20 changes: 20 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/nat_gateway.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Elastic IP for NAT Gateway
resource "aws_eip" "nat" {
domain = "vpc"

tags = {
Name = "${var.environment}-nat-eip"
Environment = var.environment
}
}

# NAT Gateway
resource "aws_nat_gateway" "main" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public[0].id

tags = {
Name = "${var.environment}-nat"
Environment = var.environment
}
}
11 changes: 11 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "vpc_id" {
value = aws_vpc.main.id
}

output "public_subnet_ids" {
value = aws_subnet.public[*].id
}

output "private_subnet_ids" {
value = aws_subnet.private[*].id
}
14 changes: 14 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/private_subnet.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Private Subnets
resource "aws_subnet" "private" {
count = length(var.availability_zones)
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index + length(var.availability_zones))
availability_zone = var.availability_zones[count.index]

tags = {
Name = "${var.environment}-private-${var.availability_zones[count.index]}"
Environment = var.environment
"kubernetes.io/cluster/${var.environment}-eks" = "shared"
"kubernetes.io/role/internal-elb" = 1
}
}
16 changes: 16 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/public_subnet.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Public Subnets
resource "aws_subnet" "public" {
count = length(var.availability_zones)
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index)
availability_zone = var.availability_zones[count.index]

map_public_ip_on_launch = true

tags = {
Name = "${var.environment}-public-${var.availability_zones[count.index]}"
Environment = var.environment
"kubernetes.io/cluster/${var.environment}-eks" = "shared"
"kubernetes.io/role/elb" = 1
}
}
1 change: 1 addition & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# modules vpc
43 changes: 43 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/route_table.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Public Route Table
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id

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

tags = {
Name = "${var.environment}-public-rt"
Environment = var.environment
}
}

# Private Route Table
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id

route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.main.id
}

tags = {
Name = "${var.environment}-private-rt"
Environment = var.environment
}
}

# Route Table Associations
resource "aws_route_table_association" "public" {
count = length(var.availability_zones)
subnet_id = aws_subnet.public[count.index].id
route_table_id = aws_route_table.public.id
}

resource "aws_route_table_association" "private" {
count = length(var.availability_zones)
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private.id
}
11 changes: 11 additions & 0 deletions aws/terraform-module-eks-cluster/modules/vpc/vpc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# VPC
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true

tags = {
Name = "vpc-${var.environment}"
Environment = var.environment
}
}
90 changes: 90 additions & 0 deletions aws/terraform-module-eks-cluster/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# terraform with teraform module eks cluster.
```
.
|-- .github
| |-- workflows
| | |-- apply-all-tf-infra.yaml
| | |-- apply-tf-infra.yaml
| | |-- destroy-tf-infra.yaml
| | |-- manual-apply-tf-infra.yaml
| | |-- plan-tf-infra.yaml
| | |-- stack-tf-infra.yaml
| | `-- uninstall-tf-infra.yaml
|-- README.md
|-- environments
| |-- local
| |-- backend.tf
| |-- main.tf
| |-- outputs.tf
| |-- providers.tf
| |-- s3-dynamodb
| | -- main.tf
| |-- variables.tf
| |-- dev
| |-- backend.tf
| |-- main.tf
| |-- outputs.tf
| |-- providers.tf
| |-- s3-dynamodb
| | -- main.tf
| |-- variables.tf
| |-- stg
| |-- backend.tf
| |-- main.tf
| |-- outputs.tf
| |-- providers.tf
| |-- s3-dynamodb
| | -- main.tf
| |-- variables.tf
| |-- prod
| |-- backend.tf
| |-- main.tf
| |-- outputs.tf
| |-- providers.tf
| |-- s3-dynamodb
| | -- main.tf
| |-- variables.tf
|-- infra
| |-- backend
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| |-- eks-fargate-karpenter
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| |-- eks-karpenter
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| |-- ec2_instance
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| |-- elasticache
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| |-- rds
| | |-- main.tf
| | |-- outputs.tf
| | `-- variables.tf
| `-- vpc
| |-- main.tf
| |-- outputs.tf
| `-- variables.tf
|-- stack
| |-- istio
| | |-- istio-ingress.yaml
| | |-- istiod-values.yaml
| | |-- pod-monitor.yaml
| | `-- service-monitor.yaml
| |-- keda
| | `-- values.yaml
| |-- metabase
| | |-- metabase-hpa.yaml
| | |-- metabase-scaling-dashboard.yaml
| | `-- values.yaml
| `-- monitoring
| `-- values.yaml
```
23 changes: 23 additions & 0 deletions aws/terraform-module-eks-cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "aws_region" {
description = "AWS region"
type = string
default = "ap-southeast-1"
}

variable "environment" {
description = "Environment name"
type = string
default = "dev"
}

variable "vpc_cidr" {
description = "CIDR block for VPC"
type = string
default = "172.28.0.0/16"
}

variable "availability_zones" {
description = "Availability zones"
type = list(string)
default = ["ap-southeast-1", "ap-southeast-1b", "ap-southeast-1"]
}