This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
116 lines (90 loc) · 2.62 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
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
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
tags = "${var.tags}"
}
module "kops_metadata" {
source = "git::https://github.com/cloudposse/terraform-aws-kops-data-iam.git?ref=tags/0.1.0"
cluster_name = "${var.cluster_name}"
}
resource "aws_iam_role" "default" {
name = "${module.label.id}"
description = "Role that can be assumed by external-dns"
lifecycle {
create_before_destroy = true
}
max_session_duration = "${var.iam_role_max_session_duration}"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
}
data "aws_iam_policy_document" "assume_role" {
statement {
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
principals {
type = "AWS"
identifiers = [
"${module.kops_metadata.masters_role_arn}",
"${module.kops_metadata.nodes_role_arn}",
]
}
effect = "Allow"
}
}
resource "aws_iam_role_policy_attachment" "default" {
role = "${aws_iam_role.default.name}"
policy_arn = "${aws_iam_policy.default.arn}"
lifecycle {
create_before_destroy = true
}
}
resource "aws_iam_policy" "default" {
name = "${module.label.id}"
description = "Grant permissions for external-dns"
policy = "${data.aws_iam_policy_document.default.json}"
}
data "aws_route53_zone" "default" {
count = "${length(var.dns_zone_names)}"
name = "${element(var.dns_zone_names, count.index)}."
private_zone = false
}
data "aws_iam_policy_document" "default" {
statement {
sid = "GrantModifyAccessToDomains"
actions = [
"route53:ChangeResourceRecordSets",
]
effect = "Allow"
resources = [
"${formatlist("arn:aws:route53:::hostedzone/%s", data.aws_route53_zone.default.*.zone_id)}",
]
}
statement {
sid = "GrantListAccessToDomains"
# route53:ListHostedZonesByName is not needed by external-dns, but is needed by cert-manager
actions = [
"route53:ListHostedZones",
"route53:ListHostedZonesByName",
"route53:ListResourceRecordSets",
]
effect = "Allow"
resources = ["*"]
}
# route53:GetChange is not needed by external-dns, but is needed by cert-manager
statement {
sid = "GrantGetChangeStatus"
actions = [
"route53:GetChange",
]
effect = "Allow"
resources = ["arn:aws:route53:::change/*"]
}
}