-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcoredns_fix.tf
80 lines (65 loc) · 1.96 KB
/
coredns_fix.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
data "archive_file" "coredns_archive" {
type = "zip"
source_dir = "files/lambda/coredns"
output_path = "files/lambda/coredns.zip"
}
resource "aws_security_group" "coredns_fix" {
name = format("%s-coredns-fargate-fix", var.cluster_name)
vpc_id = aws_vpc.cluster_vpc.id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
data "aws_iam_policy_document" "coredns_fix" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "coredns_fix" {
name_prefix = format("%s-coredns-fargate-fix", var.cluster_name)
assume_role_policy = data.aws_iam_policy_document.coredns_fix.json
}
resource "aws_iam_role_policy_attachment" "coredns_fix" {
role = aws_iam_role.coredns_fix.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}
resource "aws_lambda_function" "coredns_fix" {
function_name = format("%s-coredns-fargate-fix", var.cluster_name)
runtime = "python3.7"
handler = "main.handler"
role = aws_iam_role.coredns_fix.arn
filename = data.archive_file.coredns_archive.output_path
source_code_hash = data.archive_file.coredns_archive.output_base64sha256
timeout = 120
vpc_config {
subnet_ids = [
aws_subnet.private_subnet_1a.id,
aws_subnet.private_subnet_1b.id,
aws_subnet.private_subnet_1c.id
]
security_group_ids = [aws_security_group.coredns_fix.id]
}
}
data "aws_lambda_invocation" "coredns_fix" {
function_name = aws_lambda_function.coredns_fix.function_name
input = <<JSON
{
"endpoint": "${aws_eks_cluster.eks_cluster.endpoint}",
"token": "${data.aws_eks_cluster_auth.default.token}"
}
JSON
depends_on = [
aws_lambda_function.coredns_fix,
aws_eks_fargate_profile.kube_system
]
}