Skip to content

Commit 6f577eb

Browse files
committed
updated tf config and creating infra
1 parent d5e42db commit 6f577eb

File tree

3 files changed

+119
-102
lines changed

3 files changed

+119
-102
lines changed

.github/workflows/challenge5.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ jobs:
5050
terraform_version: 1.5.7
5151
- name: "terraform init"
5252
run: terraform init
53-
# - name: "Terraform format"
54-
# run: terraform fmt -check
55-
# - name: "Terraform validate"
56-
# run: terraform validate
57-
# - name: "Terraform plan"
58-
# run: terraform plan
59-
# - name: "terraform apply"
60-
# run: terraform apply --auto-approve
61-
# - name: "update kubeconfig"
62-
# run: aws eks update-kubeconfig --name mycluster --region us-east-1
63-
# - name: "applying config"
64-
# run: |
65-
# kubectl get nodes
66-
# kubectl apply -f kubernetes/
67-
- name: "delete cluster"
68-
run: terraform destroy --auto-approve
53+
- name: "Terraform format"
54+
run: terraform fmt -check
55+
- name: "Terraform validate"
56+
run: terraform validate
57+
- name: "Terraform plan"
58+
run: terraform plan
59+
- name: "terraform apply"
60+
run: terraform apply --auto-approve
61+
- name: "update kubeconfig"
62+
run: aws eks update-kubeconfig --name rajrishab-eks-cluster --region us-west-1
63+
- name: "applying config"
64+
run: |
65+
kubectl get nodes
66+
kubectl apply -f kubernetes/
67+
# - name: "delete cluster"
68+
# run: terraform destroy --auto-approve

challenge5/main.tf

Lines changed: 90 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,122 +12,126 @@ terraform {
1212
}
1313
}
1414

15-
# vpc
16-
resource "aws_vpc" "main" {
17-
cidr_block = "10.0.0.0/16"
18-
}
1915

20-
# 2 subnet
21-
resource "aws_subnet" "subnet1" {
22-
vpc_id = aws_vpc.main.id
23-
availability_zone = "us-east-1a"
24-
cidr_block = "10.0.1.0/24"
25-
map_public_ip_on_launch = true
16+
17+
provider "aws" {
18+
region = var.aws_region
2619
}
2720

21+
data "aws_availability_zones" "available" {}
2822

29-
resource "aws_subnet" "subnet2" {
30-
vpc_id = aws_vpc.main.id
31-
availability_zone = "us-east-1b"
32-
cidr_block = "10.0.2.0/24"
33-
map_public_ip_on_launch = true
23+
resource "aws_security_group" "all_worker_mgmt" {
24+
name_prefix = "all_worker_management"
25+
vpc_id = module.vpc.vpc_id
3426
}
3527

36-
resource "aws_subnet" "subnet3" {
37-
vpc_id = aws_vpc.main.id
38-
availability_zone = "us-east-1c"
39-
cidr_block = "10.0.3.0/24"
40-
map_public_ip_on_launch = true
28+
resource "aws_security_group_rule" "all_worker_mgmt_ingress" {
29+
description = "allow inbound traffic from eks"
30+
from_port = 0
31+
protocol = "-1"
32+
to_port = 0
33+
security_group_id = aws_security_group.all_worker_mgmt.id
34+
type = "ingress"
35+
cidr_blocks = [
36+
"10.0.0.0/8",
37+
"172.16.0.0/12",
38+
"192.168.0.0/16",
39+
]
4140
}
4241

42+
resource "aws_security_group_rule" "all_worker_mgmt_egress" {
43+
description = "allow outbound traffic to anywhere"
44+
from_port = 0
45+
protocol = "-1"
46+
security_group_id = aws_security_group.all_worker_mgmt.id
47+
to_port = 0
48+
type = "egress"
49+
cidr_blocks = ["0.0.0.0/0"]
50+
}
4351

44-
45-
# sg
46-
resource "aws_security_group" "sg1" {
47-
vpc_id = aws_vpc.main.id
48-
49-
ingress {
50-
from_port = 80
51-
to_port = 80
52-
protocol = "tcp"
53-
cidr_blocks = ["0.0.0.0/0"]
52+
module "vpc" {
53+
source = "terraform-aws-modules/vpc/aws"
54+
version = "5.7.0"
55+
56+
name = "abhi-eks-vpc"
57+
cidr = var.vpc_cidr
58+
azs = data.aws_availability_zones.available.names
59+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
60+
public_subnets = ["10.0.4.0/24", "10.0.5.0/24"]
61+
enable_nat_gateway = true
62+
single_nat_gateway = true
63+
enable_dns_hostnames = true
64+
enable_dns_support = true
65+
66+
tags = {
67+
"kubernetes.io/cluster/rajrishab-eks-cluster" = "shared"
5468
}
5569

56-
ingress {
57-
from_port = 22
58-
to_port = 22
59-
protocol = "tcp"
60-
cidr_blocks = ["0.0.0.0/0"]
70+
public_subnet_tags = {
71+
"kubernetes.io/cluster/rajrishab-eks-cluster" = "shared"
72+
"kubernetes.io/role/elb" = "1"
6173
}
6274

63-
egress {
64-
from_port = 0
65-
to_port = 0
66-
protocol = "-1"
67-
cidr_blocks = ["0.0.0.0/0"]
75+
private_subnet_tags = {
76+
"kubernetes.io/cluster/rajrishab-eks-cluster" = "shared"
77+
"kubernetes.io/role/internal-elb" = "1"
6878
}
6979

70-
7180
}
7281

82+
module "eks" {
83+
source = "terraform-aws-modules/eks/aws"
84+
version = "~> 21.0"
7385

74-
# ig
75-
resource "aws_internet_gateway" "igw1" {
76-
vpc_id = aws_vpc.main.id
77-
}
7886

79-
# route table
80-
resource "aws_route_table" "rt1" {
81-
vpc_id = aws_vpc.main.id
87+
name = "rajrishab-eks-cluster"
88+
subnet_ids = module.vpc.private_subnets
8289

83-
route {
84-
cidr_block = "10.0.0.0/16"
85-
gateway_id = "local"
86-
}
90+
enable_irsa = true
8791

88-
route {
89-
cidr_block = "0.0.0.0/0"
90-
gateway_id = aws_internet_gateway.igw1.id
92+
tags = {
93+
cluster = "demo"
9194
}
92-
}
9395

94-
resource "aws_route_table_association" "association1" {
95-
subnet_id = aws_subnet.subnet1.id
96-
route_table_id = aws_route_table.rt1.id
97-
}
96+
vpc_id = module.vpc.vpc_id
9897

9998

100-
resource "aws_route_table_association" "association2" {
101-
subnet_id = aws_subnet.subnet2.id
102-
route_table_id = aws_route_table.rt1.id
103-
}
99+
eks_managed_node_groups = {
104100

105-
resource "aws_route_table_association" "association3" {
106-
subnet_id = aws_subnet.subnet3.id
107-
route_table_id = aws_route_table.rt1.id
101+
group1 = {
102+
ami_type = "AL2_x86_64"
103+
instance_types = ["t3.medium"]
104+
vpc_security_group_ids = [aws_security_group.all_worker_mgmt.id]
105+
106+
min_size = 2
107+
max_size = 3
108+
desired_size = 2
109+
}
110+
}
108111
}
109112

110113

111-
#eks
112-
module "eks" {
113-
source = "terraform-aws-modules/eks/aws"
114-
version = "~> 21.0"
115114

115+
output "cluster_id" {
116+
description = "EKS cluster ID."
117+
value = module.eks.cluster_id
118+
}
116119

117-
name = "mycluster"
118-
kubernetes_version = "1.33"
119-
enable_cluster_creator_admin_permissions = true
120+
output "cluster_endpoint" {
121+
description = "Endpoint for EKS control plane."
122+
value = module.eks.cluster_endpoint
123+
}
120124

121-
eks_managed_node_groups = {
122-
group1 = {
123-
instance_types = ["t3.small"]
124-
min_size = 1
125-
max_size = 3
126-
desired_size = 2
127-
}
128-
}
125+
output "cluster_security_group_id" {
126+
description = "Security group ids attached to the cluster control plane."
127+
value = module.eks.cluster_security_group_id
128+
}
129+
130+
output "region" {
131+
description = "AWS region"
132+
value = var.aws_region
133+
}
129134

130-
vpc_id = aws_vpc.main.id
131-
subnet_ids = [aws_subnet.subnet1.id, aws_subnet.subnet2.id]
132-
control_plane_subnet_ids = [aws_subnet.subnet3.id, aws_subnet.subnet1.id]
133-
}
135+
output "oidc_provider_arn" {
136+
value = module.eks.oidc_provider_arn
137+
}

challenge5/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
variable "kubernetes_version" {
2+
default = 1.27
3+
description = "kubernetes version"
4+
}
5+
6+
variable "vpc_cidr" {
7+
default = "10.0.0.0/16"
8+
description = "default CIDR range of the VPC"
9+
}
10+
variable "aws_region" {
11+
default = "us-west-1"
12+
description = "aws region"
13+
}

0 commit comments

Comments
 (0)