forked from kabisa/terraform-aws-account-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudwatch-readonly-user.tf
52 lines (41 loc) · 1.25 KB
/
cloudwatch-readonly-user.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
data "aws_iam_policy_document" "monitor_readonly_user_policy_document" {
statement {
sid = "AllowReadingMetricsFromCloudWatch"
actions = [
"cloudwatch:ListMetrics",
"cloudwatch:GetMetricStatistics",
"cloudwatch:GetMetricData",
]
resources = ["*"]
}
statement {
sid = "AllowReadingTagsInstancesRegionsFromEC2"
actions = [
"ec2:DescribeTags",
"ec2:DescribeInstances",
"ec2:DescribeRegions",
]
resources = ["*"]
}
statement {
sid = "AllowReadingResourcesForTags"
actions = [
"tag:GetResources",
]
resources = ["*"]
}
}
resource "aws_iam_policy" "monitor_readonly_user_policy" {
count = var.enable_monitor_readonly_user ? 1 : 0
name = "terraform-monitor-readonly-policy"
description = "Gives readonly access to monitor and tags (e.g. for grafana)"
policy = data.aws_iam_policy_document.monitor_readonly_user_policy_document.json
}
resource "aws_iam_user" "monitor_readonly_user" {
count = var.enable_monitor_readonly_user ? 1 : 0
name = var.monitor_readonly_user_name
}
resource "aws_iam_access_key" "monitor_readonly_user_access_key" {
count = var.enable_monitor_readonly_user ? 1 : 0
user = aws_iam_user.monitor_readonly_user[0].name
}