Skip to content

Commit 857d511

Browse files
authored
Feature/eks fargate profile (#97)
* #94 bumped provider versions * #94 updated lock files * #94 updated acm, eks and r53 modules versions * #95 added fargate profile Also added cluster logs parameter for eks and moved local variables to locals.tf. * #95 fixed grafana dashboard url * #96 added fargate profile Also added cluster logs parameter for eks and moved local variables to locals.tf. * #96 moved locals for eks and vpc back to separate files * #96 decided to put only audit logs for eks as a default value
1 parent 9bed85b commit 857d511

File tree

5 files changed

+79
-62
lines changed

5 files changed

+79
-62
lines changed

terraform/layer1-aws/aws-eks.tf

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
locals {
2+
eks_map_roles = concat(var.eks_map_roles,
3+
[
4+
{
5+
rolearn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/administrator"
6+
username = "administrator"
7+
groups = [
8+
"system:masters"]
9+
}]
10+
)
11+
12+
worker_tags = [
13+
{
14+
"key" = "k8s.io/cluster-autoscaler/enabled"
15+
"propagate_at_launch" = "false"
16+
"value" = "true"
17+
},
18+
{
19+
"key" = "k8s.io/cluster-autoscaler/${local.name}"
20+
"propagate_at_launch" = "false"
21+
"value" = "true"
22+
}
23+
]
24+
}
25+
126
module "eks" {
227
source = "terraform-aws-modules/eks/aws"
328
version = "17.1.0"
@@ -7,6 +32,9 @@ module "eks" {
732
subnets = module.vpc.intra_subnets
833
enable_irsa = true
934

35+
cluster_enabled_log_types = var.eks_cluster_enabled_log_types
36+
cluster_log_retention_in_days = var.eks_cluster_log_retention_in_days
37+
1038
tags = {
1139
ClusterName = local.name
1240
Environment = local.env
@@ -33,18 +61,8 @@ module "eks" {
3361
kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot"
3462
public_ip = false
3563
additional_userdata = file("${path.module}/templates/eks-x86-nodes-userdata.sh")
36-
tags = [
37-
{
38-
"key" = "k8s.io/cluster-autoscaler/enabled"
39-
"propagate_at_launch" = "false"
40-
"value" = "true"
41-
},
42-
{
43-
"key" = "k8s.io/cluster-autoscaler/${local.name}"
44-
"propagate_at_launch" = "false"
45-
"value" = "true"
46-
}
47-
]
64+
65+
tags = local.worker_tags
4866
},
4967
{
5068
name = "ondemand"
@@ -56,18 +74,8 @@ module "eks" {
5674
kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=ondemand"
5775
public_ip = false
5876
additional_userdata = file("${path.module}/templates/eks-x86-nodes-userdata.sh")
59-
tags = [
60-
{
61-
"key" = "k8s.io/cluster-autoscaler/enabled"
62-
"propagate_at_launch" = "true"
63-
"value" = "true"
64-
},
65-
{
66-
"key" = "k8s.io/cluster-autoscaler/${local.name}"
67-
"propagate_at_launch" = "true"
68-
"value" = "true"
69-
}
70-
]
77+
78+
tags = local.worker_tags
7179
},
7280
{
7381
name = "ci"
@@ -81,27 +89,33 @@ module "eks" {
8189
kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot --node-labels=purpose=ci --register-with-taints=purpose=ci:NoSchedule"
8290
public_ip = true
8391
additional_userdata = file("${path.module}/templates/eks-x86-nodes-userdata.sh")
84-
tags = [
85-
{
86-
"key" = "k8s.io/cluster-autoscaler/enabled"
87-
"propagate_at_launch" = "false"
88-
"value" = "true"
89-
},
90-
{
91-
"key" = "k8s.io/cluster-autoscaler/${local.name}"
92-
"propagate_at_launch" = "false"
93-
"value" = "true"
94-
},
92+
93+
tags = concat(local.worker_tags, [{
94+
"key" = "k8s.io/cluster-autoscaler/node-template/label/purpose"
95+
"propagate_at_launch" = "true"
96+
"value" = "ci"
97+
}])
98+
},
99+
]
100+
101+
fargate_profiles = {
102+
default = {
103+
name = "fargate"
104+
105+
selectors = [
95106
{
96-
"key" = "k8s.io/cluster-autoscaler/node-template/label/purpose"
97-
"propagate_at_launch" = "true"
98-
"value" = "ci"
107+
namespace = "fargate"
99108
}
100109
]
101-
},
102-
]
103110

104-
map_roles = local.eks_map_roles
111+
subnets = module.vpc.private_subnets
112+
113+
tags = merge(local.tags, {
114+
Namespace = "fargate"
115+
})
116+
}
117+
}
105118

119+
map_roles = local.eks_map_roles
106120
write_kubeconfig = var.eks_write_kubeconfig
107121
}

terraform/layer1-aws/aws-vpc.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
locals {
2-
cidr_subnets = [for cidr_block in cidrsubnets(var.cidr, 2, 2, 2, 2) : cidrsubnets(cidr_block, 4, 4, 4, 4)]
3-
2+
cidr_subnets = [for cidr_block in cidrsubnets(var.cidr, 2, 2, 2, 2) : cidrsubnets(cidr_block, 4, 4, 4, 4)]
43
private_subnets = chunklist(local.cidr_subnets[0], var.az_count)[0]
54
public_subnets = chunklist(local.cidr_subnets[1], var.az_count)[0]
65
database_subnets = chunklist(local.cidr_subnets[2], var.az_count)[0]
76
intra_subnets = chunklist(local.cidr_subnets[3], var.az_count)[0]
8-
9-
azs = data.aws_availability_zones.available.names
7+
azs = data.aws_availability_zones.available.names
108
}
119

1210
module "vpc" {
@@ -79,5 +77,4 @@ module "vpc" {
7977
Name = "${local.name}-intra"
8078
destination = "intra"
8179
}
82-
8380
}

terraform/layer1-aws/locals.tf

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Use this as name base for all resources:
22
locals {
3+
# COMMON
34
env = terraform.workspace == "default" ? var.environment : terraform.workspace
45
short_region = var.short_region[var.region]
56
name = "${var.name}-${local.env}-${local.short_region}"
@@ -15,14 +16,4 @@ locals {
1516
ssl_certificate_arn = var.create_acm_certificate ? module.acm.this_acm_certificate_arn : data.aws_acm_certificate.main[0].arn
1617

1718
zone_id = var.create_r53_zone ? keys(module.r53_zone.this_route53_zone_zone_id)[0] : (var.zone_id != null ? var.zone_id : data.aws_route53_zone.main[0].zone_id)
18-
19-
eks_map_roles = concat(var.eks_map_roles,
20-
[
21-
{
22-
rolearn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/administrator"
23-
username = "administrator"
24-
groups = [
25-
"system:masters"]
26-
}]
27-
)
2819
}

terraform/layer1-aws/variables.tf

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ variable "region" {
6969
}
7070

7171
variable "az_count" {
72+
type = number
7273
description = "Count of avaiablity zones, min 2"
7374
default = 3
7475
}
@@ -136,6 +137,24 @@ variable "eks_write_kubeconfig" {
136137
description = "Flag for eks module to write kubeconfig"
137138
}
138139

140+
variable "eks_cluster_enabled_log_types" {
141+
type = list(string)
142+
default = ["audit"]
143+
description = "A list of the desired control plane logging to enable. For more information, see Amazon EKS Control Plane Logging documentation (https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html). Possible values: api, audit, authenticator, controllerManager, scheduler"
144+
}
145+
146+
variable "eks_cluster_log_retention_in_days" {
147+
type = number
148+
default = 90
149+
description = "Number of days to retain log events. Default retention - 90 days."
150+
}
151+
152+
variable "eks_cluster_encryption_config_enable" {
153+
type = bool
154+
default = false
155+
description = "Enable or not encryption for k8s secrets with aws-kms"
156+
}
157+
139158
# ECR
140159
variable "ecr_repos" {
141160
type = list(any)
@@ -144,12 +163,8 @@ variable "ecr_repos" {
144163
}
145164

146165
variable "ecr_repo_retention_count" {
166+
type = number
147167
default = 50
148168
description = "number of images to store in ECR"
149169
}
150170

151-
variable "eks_cluster_encryption_config_enable" {
152-
type = bool
153-
default = false
154-
description = "Enable or not encryption for k8s secrets with aws-kms"
155-
}

terraform/layer2-k8s/templates/prometheus-values.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ grafana:
127127
logs:
128128
logs:
129129
## Dashboard for quick search application logs for loki with two datasources loki and prometheus - https://grafana.com/grafana/dashboards/12019
130-
url: https://s3.amazonaws.com/grafana-dashboards.maddevs.org/common/aws-eks-base/loki-dashboard-quick-search.json
130+
url: https://grafana-dashboards.maddevs.org/common/aws-eks-base/loki-dashboard-quick-search.json
131131

132132
k8s:
133133
nginx-ingress:

0 commit comments

Comments
 (0)