forked from squareops/terraform-aws-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
79 lines (71 loc) · 2.14 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
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "18.29.0"
cluster_name = format("%s-%s", var.environment, var.name)
cluster_enabled_log_types = var.cluster_enabled_log_types
subnet_ids = var.private_subnet_ids
cluster_version = var.cluster_version
enable_irsa = true
tags = {
"Name" = format("%s-%s", var.environment, var.name)
"Environment" = var.environment
}
vpc_id = var.vpc_id
cloudwatch_log_group_retention_in_days = var.cluster_log_retention_in_days
cluster_endpoint_private_access = var.cluster_endpoint_public_access ? false : true
cluster_endpoint_public_access = var.cluster_endpoint_public_access
cluster_endpoint_public_access_cidrs = var.cluster_endpoint_public_access_cidrs
cluster_encryption_config = [
{
provider_key_arn = var.kms_key_arn
resources = ["secrets"]
}
]
}
resource "aws_iam_policy" "kubernetes_pvc_kms_policy" {
name = format("%s-%s", var.name, "kubernetes-pvc-kms-policy")
description = "Allow kubernetes pvc to get access of KMS."
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kms:CreateGrant",
"kms:Decrypt",
"kms:GenerateDataKeyWithoutPlaintext"
],
"Resource": "${var.kms_key_arn}"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "eks_kms_cluster_policy_attachment" {
role = module.eks.cluster_iam_role_name
policy_arn = aws_iam_policy.kubernetes_pvc_kms_policy.arn
}
resource "aws_iam_role" "node_role" {
name = format("%s-%s-node-role", var.environment, var.name)
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
tags = merge(
{ "Name" = format("%s-%s-node-role", var.environment, var.name)
"Environment" = var.environment
}
)
}