Skip to content

Commit ff5e61b

Browse files
committed
fix(tfvars): remove secrets
1 parent fa7552d commit ff5e61b

File tree

1 file changed

+176
-0
lines changed
  • app/template_generators/terraform/tfvars

1 file changed

+176
-0
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
2+
3+
def grafana_tfvars(input):
4+
5+
grafana_connection = """{
6+
"url" = "http://localhost:8080",
7+
"auth" = ""
8+
}"""
9+
slack_contact_point = """
10+
{
11+
url = "https://hooks.slack.com/<YOUR_SLACK_WEBHOOK_URL>"
12+
text = <<EOT
13+
{{ len .Alerts.Firing }} alerts are firing
14+
15+
Alert summaries:
16+
{{ range .Alerts.Firing }}
17+
{{ template "Alert Instance Template" . }}
18+
{{ end }}
19+
EOT
20+
}
21+
22+
"""
23+
24+
mute_timing = """
25+
{
26+
name = "My Mute Timing"
27+
start = "04:56"
28+
end = "04:57"
29+
weekdays = ["monday", "tuesday:thursday"]
30+
days_of_month = ["1:7", "-1"]
31+
months = ["1:3", "december"]
32+
years = []
33+
}
34+
35+
"""
36+
37+
notification_policy_config = """
38+
{
39+
group_by = ["..."]
40+
group_wait = "45s"
41+
group_interval = "6m"
42+
repeat_interval = "3h"
43+
}
44+
45+
"""
46+
47+
policies = """
48+
{
49+
matchers = [
50+
{ label = "mylabel", match = "=", value = "myvalue" },
51+
{ label = "alertname", match = "=", value = "CPU Usage" },
52+
{ label = "Name", match = "=~", value = "host.*|host-b.*" }
53+
]
54+
contact_point = "a_contact_point_1"
55+
continue = true
56+
mute_timings = ["mute_timing_1"]
57+
group_by = ["group1_sub"]
58+
},
59+
{
60+
matchers = [
61+
{ label = "sublabel", match = "=", value = "subvalue" }
62+
]
63+
contact_point = "a_contact_point_1"
64+
continue = false
65+
mute_timings = ["mute_timing_2"]
66+
group_by = ["group2_sub"]
67+
}
68+
69+
"""
70+
71+
if input.create_contact_point is None:
72+
tfvars_file = f'''
73+
# Grafana Connection Variables
74+
grafana_connection = {grafana_connection}
75+
76+
77+
# Grafana_Contact_Point Variables
78+
create_contact_point = false
79+
contact_point_name = "My Contact Point"
80+
81+
email_contact_point = {{
82+
83+
message = "{{ len .Alerts.Firing }} firing."
84+
subject = "{{ template \"default.title\" .}}"
85+
single_email = true
86+
disable_resolve_message = false
87+
}}
88+
89+
slack_contact_point = {slack_contact_point}
90+
# Use {{ template "Alert Instance Template" . }} or any other template if you plan \
91+
# to create one. Otherwise, remove it from the text section of Slack in the above example
92+
93+
94+
# Grafana_Message_Template Variables
95+
create_message_template = {str(input.create_message_template).lower()}
96+
message_template_name = "Alert Instance Template"
97+
message_template_content = <<EOT
98+
{{ define "Alert Instance Template" }}
99+
Firing: {{ .Labels.alertname }}
100+
Silence: {{ .SilenceURL }}
101+
{{ end }}
102+
EOT
103+
104+
105+
# Grafana_Mute_Timing Variables
106+
create_mute_timing = {str(input.create_mute_timing).lower()}
107+
mute_timing = {mute_timing}
108+
109+
110+
# Grafana_Notification_Policy Variables
111+
create_notification_policy = {str(input.create_notification_policy).lower()}
112+
notification_policy_config = {notification_policy_config}
113+
policies = []
114+
/* policies = [
115+
{policies}
116+
] */
117+
118+
119+
'''
120+
121+
return tfvars_file
122+
123+
else:
124+
125+
126+
tfvars_file = f"""
127+
# Grafana Connection Variables
128+
grafana_connection = {grafana_connection}
129+
130+
131+
# Grafana_Contact_Point Variables
132+
create_contact_point = true
133+
contact_point_name = "My Contact Point"
134+
use_email = {str(input.create_contact_point.use_email).lower()}
135+
use_slack = {str(input.create_contact_point.use_slack).lower()}
136+
email_contact_point = {{
137+
138+
message = "{{ len .Alerts.Firing }} firing."
139+
subject = "{{ template \"default.title\" .}}"
140+
single_email = true
141+
disable_resolve_message = false
142+
}}
143+
144+
slack_contact_point = {slack_contact_point}
145+
# Use {{ template "Alert Instance Template" . }} or any other template if you plan \
146+
# to create one. Otherwise, remove it from the text section of Slack in the above example
147+
148+
149+
# Grafana_Message_Template Variables
150+
create_message_template = {str(input.create_message_template).lower()}
151+
message_template_name = "Alert Instance Template"
152+
message_template_content = <<EOT
153+
{{ define "Alert Instance Template" }}
154+
Firing: {{ .Labels.alertname }}
155+
Silence: {{ .SilenceURL }}
156+
{{ end }}
157+
EOT
158+
159+
160+
# Grafana_Mute_Timing Variables
161+
create_mute_timing = {str(input.create_mute_timing).lower()}
162+
mute_timing = {mute_timing}
163+
164+
165+
# Grafana_Notification_Policy Variables
166+
create_notification_policy = {str(input.create_notification_policy).lower()}
167+
notification_policy_config = {notification_policy_config}
168+
policies = []
169+
/* policies = [
170+
{policies}
171+
] */
172+
173+
174+
"""
175+
176+
return tfvars_file

0 commit comments

Comments
 (0)