forked from helium/helium-foundation-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal_dns.tf
117 lines (110 loc) · 2.8 KB
/
external_dns.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
locals {
oidc_url = replace(data.aws_eks_cluster.eks.identity[0].oidc[0].issuer, "https://", "")
}
resource "aws_iam_role" "external_dns" {
name = "${local.cluster_name}-external-dns"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.oidc_url}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${local.oidc_url}:sub": "system:serviceaccount:kube-system:external-dns"
}
}
}
]
}
EOF
}
resource "aws_iam_role_policy" "external_dns" {
name_prefix = "${local.cluster_name}-external-dns"
role = aws_iam_role.external_dns.name
policy = file("${path.module}/policies/external-dns-iam-policy.json")
}
resource "kubernetes_cluster_role" "external_dns" {
metadata {
name = "external-dns"
}
rule {
api_groups = [""]
resources = ["services"]
verbs = ["get", "list", "watch"]
}
rule {
api_groups = [""]
resources = ["pods"]
verbs = ["get", "list", "watch"]
}
rule {
api_groups = ["networking", "networking.k8s.io"]
resources = ["ingresses"]
verbs = ["get", "list", "watch"]
}
rule {
api_groups = [""]
resources = ["nodes"]
verbs = ["get", "list", "watch"]
}
rule {
api_groups = [""]
resources = ["endpoints"]
verbs = ["get", "list", "watch"]
}
}
resource "kubernetes_cluster_role_binding" "external_dns" {
metadata {
name = "external-dns"
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role.external_dns.metadata.0.name
}
subject {
kind = "ServiceAccount"
name = kubernetes_service_account.external_dns.metadata.0.name
namespace = kubernetes_service_account.external_dns.metadata.0.namespace
}
}
resource "kubectl_manifest" "external_dns" {
yaml_body = <<YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: external-dns
namespace: kube-system
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: external-dns
template:
metadata:
labels:
app: external-dns
spec:
securityContext:
fsGroup: 65534
serviceAccountName: external-dns
containers:
- name: external-dns
image: k8s.gcr.io/external-dns/external-dns:v0.10.2
args:
- --source=service
- --source=ingress
- --provider=aws
- --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
- --aws-zone-type=
- --registry=txt
- --log-level=debug
- --txt-owner-id=${var.zone_id}
YAML
}