-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiam.tf
100 lines (94 loc) · 3.1 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
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
/**
* Copyright (c) 2017-present SIGHUP s.r.l All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
data "aws_eks_cluster" "this" {
name = var.cluster_name
}
resource "aws_iam_policy" "external_dns_public" {
name = "${var.cluster_name}-e-dns-public"
tags = var.tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetHostedZone",
"route53:GetHostedZoneCount",
"route53:ListHostedZonesByName",
"route53:ListHostedZones",
"route53:ListResourceRecordSets"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"route53:ChangeResourceRecordSets"
],
"Resource": [
"arn:aws:route53:::hostedzone/${var.public_zone_id}"
]
}
]
}
EOF
}
module "external_dns_public_iam_assumable_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "v3.16.0"
create_role = true
role_name = "${var.cluster_name}-e-dns-public"
provider_url = replace(data.aws_eks_cluster.this.identity.0.oidc.0.issuer, "https://", "")
role_policy_arns = [aws_iam_policy.external_dns_public.arn]
oidc_fully_qualified_subjects = ["system:serviceaccount:ingress-nginx:external-dns-public"]
}
resource "aws_iam_policy" "external_dns_private" {
count = var.enable_private ? 1 : 0
name = "${var.cluster_name}-e-dns-private"
tags = var.tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetHostedZone",
"route53:GetHostedZoneCount",
"route53:ListHostedZonesByName",
"route53:ListHostedZones",
"route53:ListResourceRecordSets"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"route53:ChangeResourceRecordSets"
],
"Resource": [
"arn:aws:route53:::hostedzone/${var.private_zone_id}"
]
}
]
}
EOF
}
module "external_dns_private_iam_assumable_role" {
count = var.enable_private ? 1 : 0
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "v3.16.0"
create_role = true
role_name = "${var.cluster_name}-e-dns-private"
provider_url = replace(data.aws_eks_cluster.this.identity.0.oidc.0.issuer, "https://", "")
role_policy_arns = [aws_iam_policy.external_dns_private[0].arn]
oidc_fully_qualified_subjects = ["system:serviceaccount:ingress-nginx:external-dns-private"]
}