-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
190 lines (156 loc) · 4.45 KB
/
main.tf
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# terraform init -backend-config="bucket=<BUCKET-NAME>" -backend-config="key=<path/to/terraform.tfstate>" -backend-config="region=<REGION>"
terraform {
backend "s3" {
bucket = ""
key = ""
region = ""
}
}
provider "aws" {
region = var.aws_region
}
# AWS EKS Cluster
resource "aws_eks_cluster" "reportportal" {
depends_on = [aws_cloudwatch_log_group.reportportal]
name = "${var.prj_code}-reportportal-${var.cluster_env}-eks"
role_arn = var.cluster_iam_role
version = var.cluster_version
enabled_cluster_log_types = ["api", "audit"]
vpc_config {
subnet_ids = var.vpc_subnets
security_group_ids = var.vpc_security_groups
endpoint_private_access = var.private_access
endpoint_public_access = var.public_access
}
tags = {
"Environment" = var.cluster_env
"Owner" = "terraform"
}
}
resource "aws_cloudwatch_log_group" "reportportal" {
# The log group name format is /aws/eks/<cluster-name>/cluster
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html
name = "/aws/eks/${var.prj_code}-reportportal-${var.cluster_env}-eks/cluster"
retention_in_days = 7
}
# AWS EKS Node Group
# API Node Group
resource "aws_eks_node_group" "reportportal-api" {
cluster_name = aws_eks_cluster.reportportal.name
node_group_name = "${var.prj_code}-api-${var.cluster_env}-nodegroup"
node_role_arn = var.nodegroup_iam_role
subnet_ids = var.vpc_subnets
instance_types = var.nodegroup_shape_service_api
capacity_type = "ON_DEMAND"
disk_size = "50"
labels = {
"service" = "api"
}
scaling_config {
desired_size = 2
max_size = 3
min_size = 2
}
update_config {
max_unavailable = 1
}
remote_access {
ec2_ssh_key = var.nodegroup_ssh_key
source_security_group_ids = var.vpc_security_groups
}
tags = {
"Environment" = var.cluster_env
"Owner" = "terraform"
"NodeGroup" = "api"
}
}
# RabbitMQ Node Group
resource "aws_eks_node_group" "reportportal-rabbitmq" {
cluster_name = aws_eks_cluster.reportportal.name
node_group_name = "${var.prj_code}-rabbitmq-${var.cluster_env}-nodegroup"
node_role_arn = var.nodegroup_iam_role
subnet_ids = var.vpc_subnets
instance_types = var.nodegroup_shape_service_rabbitmq
capacity_type = "ON_DEMAND"
disk_size = "50"
labels = {
"service" = "rabbitmq"
}
scaling_config {
desired_size = 1
max_size = 1
min_size = 1
}
update_config {
max_unavailable = 1
}
remote_access {
ec2_ssh_key = var.nodegroup_ssh_key
source_security_group_ids = var.vpc_security_groups
}
tags = {
"Environment" = var.cluster_env
"Owner" = "terraform"
"NodeGroup" = "rabbitmq"
}
}
# ElasticSearch Node Group
resource "aws_eks_node_group" "reportportal-elastic" {
cluster_name = aws_eks_cluster.reportportal.name
node_group_name = "${var.prj_code}-elastic-${var.cluster_env}-nodegroup"
node_role_arn = var.nodegroup_iam_role
subnet_ids = var.vpc_subnets
instance_types = var.nodegroup_shape_service_elastic
capacity_type = "ON_DEMAND"
disk_size = "50"
labels = {
"service" = "elasticsearch"
}
scaling_config {
desired_size = 3
max_size = 4
min_size = 3
}
update_config {
max_unavailable = 1
}
remote_access {
ec2_ssh_key = var.nodegroup_ssh_key
source_security_group_ids = var.vpc_security_groups
}
tags = {
"Environment" = var.cluster_env
"Owner" = "terraform"
"NodeGroup" = "elasticsearch"
}
}
# Monitoring Node Group
resource "aws_eks_node_group" "reportportal-monitoring" {
cluster_name = aws_eks_cluster.reportportal.name
node_group_name = "${var.prj_code}-monitoring-${var.cluster_env}-nodegroup"
node_role_arn = var.nodegroup_iam_role
subnet_ids = var.vpc_subnets
instance_types = var.nodegroup_shape_service_elastic
capacity_type = "ON_DEMAND"
disk_size = "20"
labels = {
"service" = "monitoring"
}
scaling_config {
desired_size = 1
max_size = 1
min_size = 1
}
update_config {
max_unavailable = 1
}
remote_access {
ec2_ssh_key = var.nodegroup_ssh_key
source_security_group_ids = var.vpc_security_groups
}
tags = {
"Environment" = var.cluster_env
"Owner" = "terraform"
"NodeGroup" = "monitoring"
}
}