-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
101 lines (80 loc) · 2.18 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
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
}
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"
actions = [
"route53:ListHostedZones",
"route53:ListResourceRecordSets",
]
effect = "Allow"
resources = [
"*",
]
}
}