This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
151 lines (140 loc) · 4.94 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//TODO: Move the grafana module in the `modules/grafana` folder
module "managed_grafana" {
# This is a fork of the upstream community edition and will be set back to the published
# module version once the fix for adding `nac_configuration` is merged upstream.
source = "github.com/liatrio/terraform-aws-managed-service-grafana.git"
#version = "1.8.0"
name = var.name
associate_license = false
description = local.description
account_access_type = var.account_access_type
authentication_providers = var.authentication_providers
permission_type = "SERVICE_MANAGED"
data_sources = var.data_sources
notification_destinations = ["SNS"]
stack_set_name = var.name
create = var.create
create_workspace = var.create_workspace
configuration = jsonencode({
unifiedAlerting = {
enabled = true
}
plugins = {
pluginAdminEnabled = false
}
})
# Workspace IAM role
create_iam_role = var.create_iam_role ? true : false
iam_role_name = var.iam_role_name
use_iam_role_name_prefix = var.use_iam_role_name_prefix
iam_role_description = local.description
iam_role_path = "/grafana/"
iam_role_force_detach_policies = true
iam_role_max_session_duration = 7200
iam_role_tags = var.tags
tags = var.tags
# SAML configuration settings
create_saml_configuration = var.create_saml_configuration
saml_admin_role_values = var.create_saml_configuration ? var.saml_admin_role_values : []
saml_editor_role_values = var.create_saml_configuration ? var.saml_editor_role_values : []
saml_email_assertion = var.create_saml_configuration ? var.saml_email_assertion : ""
saml_groups_assertion = var.create_saml_configuration ? var.saml_groups_assertion : ""
saml_login_assertion = var.create_saml_configuration ? var.saml_login_assertion : ""
saml_name_assertion = var.create_saml_configuration ? var.saml_name_assertion : ""
saml_org_assertion = var.create_saml_configuration ? var.saml_org_assertion : ""
saml_role_assertion = var.create_saml_configuration ? var.saml_role_assertion : ""
saml_idp_metadata_url = var.create_saml_configuration && var.generate_metadata_url ? local.idp_metadata_url : var.saml_idp_metadata_url
# vpc & nac configuration
vpc_configuration = var.vpc_configuration
nac_configuration = var.nac_configuration
}
resource "aws_iam_role_policy" "grafana_xray_policy" {
depends_on = [module.managed_grafana]
name = "GrafanaXrayDatasourcePolicy-${var.environment}"
role = module.managed_grafana.workspace_iam_role_name
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "AllowReadingMetricsFromCloudWatch",
"Effect" : "Allow",
"Action" : [
"cloudwatch:DescribeAlarmsForMetric",
"cloudwatch:DescribeAlarmHistory",
"cloudwatch:DescribeAlarms",
"cloudwatch:ListMetrics",
"cloudwatch:GetMetricData",
"cloudwatch:GetInsightRuleReport"
],
"Resource" : "*"
},
{
"Sid" : "AllowReadingLogsFromCloudWatch",
"Effect" : "Allow",
"Action" : [
"logs:DescribeLogGroups",
"logs:GetLogGroupFields",
"logs:StartQuery",
"logs:StopQuery",
"logs:GetQueryResults",
"logs:GetLogEvents"
],
"Resource" : "*"
},
{
"Sid" : "AllowReadingTagsInstancesRegionsFromEC2",
"Effect" : "Allow",
"Action" : [
"ec2:DescribeTags",
"ec2:DescribeInstances",
"ec2:DescribeRegions"
],
"Resource" : "*"
},
{
"Sid" : "AllowReadingResourcesForTags",
"Effect" : "Allow",
"Action" : "tag:GetResources",
"Resource" : "*"
},
{
"Action" : [
"oam:ListSinks",
"oam:ListAttachedLinks"
],
"Effect" : "Allow",
"Resource" : "*"
},
{
"Effect" : "Allow",
"Action" : [
"xray:BatchGetTraces",
"xray:GetTraceSummaries",
"xray:GetTraceGraph",
"xray:GetGroups",
"xray:GetTimeSeriesServiceStatistics",
"xray:GetInsightSummaries",
"xray:GetInsight",
"xray:GetServiceGraph",
"ec2:DescribeRegions"
],
"Resource" : "*"
},
{
"Effect" : "Allow",
"Action" : [
"aps:ListRules",
"aps:ListAlertManagerSilences",
"aps:ListAlertManagerAlerts",
"aps:GetAlertManagerStatus",
"aps:ListAlertManagerAlertGroups",
"aps:PutAlertManagerSilences",
"aps:DeleteAlertManagerSilence"
],
"Resource" : "*"
}
]
})
}