-
Notifications
You must be signed in to change notification settings - Fork 5
/
iam.tf
49 lines (41 loc) · 1.34 KB
/
iam.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
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "eks_assume_role" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
identifiers = ["eks.amazonaws.com"]
type = "Service"
}
}
}
resource "aws_iam_role" "external_dns" {
name = "aws-eks-external-dns-viewer-${lower(var.hosted_zone_id)}-${lower(var.k8s_cluster_name)}"
description = "Permissions required by the Kubernetes AWS EKS External Name controller to do it's job."
path = "/"
assume_role_policy = data.aws_iam_policy_document.eks_assume_role.json
}
data "aws_iam_policy_document" "external_dns" {
statement {
actions = [
"route53:ChangeResourceRecordSets",
]
resources = ["arn:aws:route53:::hostedzone/*"]
}
statement {
actions = [
"route53:ListHostedZones",
"route53:ListResourceRecordSets",
]
resources = ["*"]
}
}
resource "aws_iam_policy" "external_dns" {
name = "aws-eks-external-dns-viewer-${lower(var.hosted_zone_id)}-${lower(var.k8s_cluster_name)}"
description = "Allows access to resources needed to run external dns."
policy = data.aws_iam_policy_document.external_dns.json
}
resource "aws_iam_role_policy_attachment" "external_dns" {
role = aws_iam_role.external_dns.name
policy_arn = aws_iam_policy.external_dns.arn
}