-
Notifications
You must be signed in to change notification settings - Fork 45
/
iam_managed_prometheus.tf
63 lines (50 loc) · 1.49 KB
/
iam_managed_prometheus.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
data "aws_iam_policy_document" "managed_prometheus_role" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub"
values = [
"system:serviceaccount:prometheus:managed-prometheus"
]
}
principals {
identifiers = [aws_iam_openid_connect_provider.eks.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "managed_prometheus_role" {
assume_role_policy = data.aws_iam_policy_document.managed_prometheus_role.json
name = format("%s-managed-prometheus", var.cluster_name)
}
data "aws_iam_policy_document" "managed_prometheus_policy" {
version = "2012-10-17"
statement {
effect = "Allow"
actions = [
"aps:QueryMetrics",
"aps:GetSeries",
"aps:GetLabels",
"aps:GetMetricMetadata",
"aps:RemoteWrite"
]
resources = [
"*"
]
}
}
resource "aws_iam_policy" "managed_prometheus_policy" {
name = format("%s-managed-prometheus", var.cluster_name)
path = "/"
description = var.cluster_name
policy = data.aws_iam_policy_document.managed_prometheus_policy.json
}
resource "aws_iam_policy_attachment" "managed_prometheus_policy" {
name = format("%s-managed-prometheus", var.cluster_name)
roles = [
aws_iam_role.managed_prometheus_role.name
]
policy_arn = aws_iam_policy.managed_prometheus_policy.arn
}