-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
62 lines (47 loc) · 1.79 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">=5.82.2"
}
}
}
data "aws_caller_identity" "identity" {}
resource "aws_eks_cluster" "cluster" {
name = var.cluster_name
role_arn = "arn:aws:iam::${data.aws_caller_identity.identity.account_id}:role/${var.cluster_role_name}"
version = var.kubernetes_version
vpc_config {
subnet_ids = setunion(var.public_subnet_ids, var.private_subnet_ids)
security_group_ids = var.additional_cluster_security_group_ids
}
upgrade_policy {
support_type = var.support_type
}
}
resource "aws_eks_fargate_profile" "fargate_profiles" {
for_each = { for profile in var.fargate_profiles : profile.name => profile }
cluster_name = aws_eks_cluster.cluster.name
fargate_profile_name = each.value.name
pod_execution_role_arn = "arn:aws:iam::${data.aws_caller_identity.identity.account_id}:role/${coalesce(each.value.pod_execution_role_name, "AmazonEKSFargatePodExecutionRole")}"
subnet_ids = coalesce(each.value.subnet_ids, var.private_subnet_ids)
dynamic "selector" {
for_each = each.value.selectors
content {
namespace = selector.value.namespace
labels = selector.value.labels
}
}
}
resource "aws_eks_node_group" "node_groups" {
for_each = { for group in var.node_groups : group.name => group }
cluster_name = aws_eks_cluster.cluster.name
node_group_name = each.value.name
node_role_arn = "arn:aws:iam::${data.aws_caller_identity.identity.account_id}:role/${coalesce(each.value.node_role_name, "AmazonEKSNodeRole")}"
subnet_ids = each.value.subnet_ids
scaling_config {
desired_size = each.value.scaling_config.desired_size
max_size = each.value.scaling_config.max_size
min_size = each.value.scaling_config.min_size
}
}