-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
136 lines (108 loc) · 3.14 KB
/
Copy pathmain.tf
File metadata and controls
136 lines (108 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Main Terraform configuration for AgentGuard Infrastructure
# This file orchestrates the composition of all infrastructure modules
# AWS Provider Configuration
provider "aws" {
region = var.region
}
# VPC Module - Provisions minimal-cost VPC networking with public subnets
module "vpc" {
source = "./modules/vpc"
vpc_cidr = var.vpc_cidr
cluster_name = var.cluster_name
availability_zones = var.availability_zones
public_subnet_cidrs = var.public_subnet_cidrs
}
# EKS Module - Provisions EKS control plane with minimal IAM configuration
module "eks" {
source = "./modules/eks"
cluster_name = var.cluster_name
cluster_version = var.cluster_version
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.public_subnet_ids
depends_on = [module.vpc]
}
# Node Group Module - Provisions cost-optimized managed node group with t2.micro instances
module "node_group" {
source = "./modules/node-group"
cluster_name = module.eks.cluster_id
node_group_name = "${var.cluster_name}-node-group"
subnet_ids = module.vpc.public_subnet_ids
instance_types = var.node_instance_types
desired_size = var.node_desired_size
min_size = var.node_min_size
max_size = var.node_max_size
disk_size = var.node_disk_size
depends_on = [module.eks]
}
# Data source for EKS cluster authentication
data "aws_eks_cluster_auth" "main" {
name = module.eks.cluster_id
}
# Kubernetes Provider Configuration - Uses EKS cluster credentials for post-deployment validation
provider "kubernetes" {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_ca_certificate)
token = data.aws_eks_cluster_auth.main.token
}
# Validation Deployment - Nginx deployment to verify cluster functionality
resource "kubernetes_deployment" "validation" {
metadata {
name = "nginx-validation"
labels = {
app = "nginx-validation"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "nginx-validation"
}
}
template {
metadata {
labels = {
app = "nginx-validation"
}
}
spec {
container {
name = "nginx"
image = "nginx:latest"
port {
container_port = 80
}
resources {
requests = {
cpu = "100m"
memory = "128Mi"
}
limits = {
cpu = "200m"
memory = "256Mi"
}
}
}
}
}
}
depends_on = [module.node_group]
}
# Validation Service - LoadBalancer service to validate AWS ELB integration
resource "kubernetes_service" "validation" {
metadata {
name = "nginx-validation-lb"
}
spec {
selector = {
app = "nginx-validation"
}
port {
port = 80
target_port = 80
protocol = "TCP"
}
type = "LoadBalancer"
}
depends_on = [kubernetes_deployment.validation]
}