Skip to content

Commit a4e6a6a

Browse files
committed
feat(tests): Add Grafana tests
1 parent b74867f commit a4e6a6a

File tree

3 files changed

+386
-0
lines changed

3 files changed

+386
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
grafana
2+
| app.bicep:5:1:12:1 | GrafanaResource |
3+
| app.bicep:15:1:24:1 | GrafanaResource |
4+
| app.bicep:15:1:24:1 | Public Grafana Resource |
5+
| app.bicep:27:1:36:1 | GrafanaResource |
6+
| app.bicep:39:1:49:1 | GrafanaResource |
7+
| app.bicep:52:1:65:1 | GrafanaResource |
8+
| app.bicep:68:1:92:1 | GrafanaResource |
9+
| app.bicep:68:1:92:1 | Public Grafana Resource |
10+
| app.bicep:95:1:107:1 | GrafanaResource |
11+
| app.bicep:110:1:123:1 | GrafanaResource |
12+
| app.bicep:126:1:146:1 | GrafanaResource |
13+
| app.bicep:149:1:162:1 | GrafanaResource |
14+
| app.bicep:165:1:178:1 | GrafanaResource |
15+
| app.bicep:181:1:195:1 | GrafanaResource |
16+
| app.bicep:198:1:216:1 | GrafanaResource |
17+
| app.bicep:219:1:231:1 | GrafanaResource |
18+
| app.bicep:234:1:305:1 | GrafanaResource |
19+
| app.bicep:234:1:305:1 | Public Grafana Resource |
20+
| app.bicep:308:1:317:1 | GrafanaResource |
21+
publicGrafana
22+
| app.bicep:15:1:24:1 | GrafanaResource |
23+
| app.bicep:15:1:24:1 | Public Grafana Resource |
24+
| app.bicep:68:1:92:1 | GrafanaResource |
25+
| app.bicep:68:1:92:1 | Public Grafana Resource |
26+
| app.bicep:234:1:305:1 | GrafanaResource |
27+
| app.bicep:234:1:305:1 | Public Grafana Resource |
28+
grafanaProperties
29+
| app.bicep:5:1:12:1 | GrafanaResource | app.bicep:8:15:8:16 | GrafanaProperties |
30+
| app.bicep:15:1:24:1 | GrafanaResource | app.bicep:18:15:20:3 | GrafanaProperties |
31+
| app.bicep:15:1:24:1 | Public Grafana Resource | app.bicep:18:15:20:3 | GrafanaProperties |
32+
| app.bicep:27:1:36:1 | GrafanaResource | app.bicep:30:15:32:3 | GrafanaProperties |
33+
| app.bicep:39:1:49:1 | GrafanaResource | app.bicep:45:15:45:16 | GrafanaProperties |
34+
| app.bicep:52:1:65:1 | GrafanaResource | app.bicep:61:15:61:16 | GrafanaProperties |
35+
| app.bicep:68:1:92:1 | GrafanaResource | app.bicep:77:15:84:3 | GrafanaProperties |
36+
| app.bicep:68:1:92:1 | Public Grafana Resource | app.bicep:77:15:84:3 | GrafanaProperties |
37+
| app.bicep:95:1:107:1 | GrafanaResource | app.bicep:98:15:103:3 | GrafanaProperties |
38+
| app.bicep:110:1:123:1 | GrafanaResource | app.bicep:113:15:119:3 | GrafanaProperties |
39+
| app.bicep:126:1:146:1 | GrafanaResource | app.bicep:129:15:142:3 | GrafanaProperties |
40+
| app.bicep:149:1:162:1 | GrafanaResource | app.bicep:152:15:158:3 | GrafanaProperties |
41+
| app.bicep:165:1:178:1 | GrafanaResource | app.bicep:168:15:174:3 | GrafanaProperties |
42+
| app.bicep:181:1:195:1 | GrafanaResource | app.bicep:184:15:191:3 | GrafanaProperties |
43+
| app.bicep:198:1:216:1 | GrafanaResource | app.bicep:201:15:212:3 | GrafanaProperties |
44+
| app.bicep:219:1:231:1 | GrafanaResource | app.bicep:222:15:227:3 | GrafanaProperties |
45+
| app.bicep:234:1:305:1 | GrafanaResource | app.bicep:243:15:295:3 | GrafanaProperties |
46+
| app.bicep:234:1:305:1 | Public Grafana Resource | app.bicep:243:15:295:3 | GrafanaProperties |
47+
| app.bicep:308:1:317:1 | GrafanaResource | app.bicep:311:15:313:3 | GrafanaProperties |
48+
grafanaEnterpriseConfig
49+
| app.bicep:95:1:107:1 | GrafanaResource | app.bicep:99:31:102:5 | EnterpriseConfigurations |
50+
| app.bicep:234:1:305:1 | GrafanaResource | app.bicep:250:31:253:5 | EnterpriseConfigurations |
51+
| app.bicep:234:1:305:1 | Public Grafana Resource | app.bicep:250:31:253:5 | EnterpriseConfigurations |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
private import bicep
2+
3+
query predicate grafana(Dashboards::GrafanaResource grafana) { any() }
4+
5+
query predicate publicGrafana(Dashboards::PublicGrafanaResource publicGrafana) { any() }
6+
7+
query predicate grafanaProperties(
8+
Dashboards::GrafanaResource grafana, Dashboards::GrafanaProperties::Properties properties
9+
) {
10+
grafana.getProperties() = properties
11+
}
12+
13+
query predicate grafanaEnterpriseConfig(
14+
Dashboards::GrafanaResource grafana,
15+
Dashboards::GrafanaProperties::EnterpriseConfigurations enterpriseConfig
16+
) {
17+
grafana.getProperties().getEnterpriseConfigurations() = enterpriseConfig
18+
}
Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
// Example of Microsoft.Dashboard/grafana resources
2+
// This file contains multiple examples to test all the properties defined in our CodeQL module
3+
4+
// Basic grafana resource with minimum required properties
5+
resource basicGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
6+
name: 'basic-grafana'
7+
location: 'westus2'
8+
properties: {}
9+
sku: {
10+
name: 'Standard'
11+
}
12+
}
13+
14+
// Grafana with public network access enabled - used to test PublicGrafanaResource class
15+
resource publicGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
16+
name: 'public-grafana'
17+
location: 'eastus'
18+
properties: {
19+
publicNetworkAccess: 'Enabled'
20+
}
21+
sku: {
22+
name: 'Standard'
23+
}
24+
}
25+
26+
// Grafana with public network access explicitly disabled
27+
resource privateGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
28+
name: 'private-grafana'
29+
location: 'westeurope'
30+
properties: {
31+
publicNetworkAccess: 'Disabled'
32+
}
33+
sku: {
34+
name: 'Standard'
35+
}
36+
}
37+
38+
// Grafana with identity configuration
39+
resource identityGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
40+
name: 'identity-grafana'
41+
location: 'eastus2'
42+
identity: {
43+
type: 'SystemAssigned'
44+
}
45+
properties: {}
46+
sku: {
47+
name: 'Standard'
48+
}
49+
}
50+
51+
// Grafana with user assigned identity
52+
resource userIdentityGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
53+
name: 'user-identity-grafana'
54+
location: 'westus'
55+
identity: {
56+
type: 'UserAssigned'
57+
userAssignedIdentities: {
58+
'/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity': {}
59+
}
60+
}
61+
properties: {}
62+
sku: {
63+
name: 'Standard'
64+
}
65+
}
66+
67+
// Comprehensive Grafana resource with all main properties
68+
resource comprehensiveGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
69+
name: 'comprehensive-grafana'
70+
location: 'centralus'
71+
identity: {
72+
type: 'SystemAssigned,UserAssigned'
73+
userAssignedIdentities: {
74+
'/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity': {}
75+
}
76+
}
77+
properties: {
78+
apiKey: 'Enabled'
79+
autoGeneratedDomainNameLabelScope: 'TenantReuse'
80+
deterministicOutboundIP: 'Enabled'
81+
grafanaMajorVersion: '10'
82+
publicNetworkAccess: 'Enabled'
83+
zoneRedundancy: 'Enabled'
84+
}
85+
sku: {
86+
name: 'Standard'
87+
}
88+
tags: {
89+
Environment: 'Production'
90+
Department: 'IT'
91+
}
92+
}
93+
94+
// Grafana with enterprise configurations
95+
resource enterpriseGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
96+
name: 'enterprise-grafana'
97+
location: 'northeurope'
98+
properties: {
99+
enterpriseConfigurations: {
100+
marketplaceAutoRenew: 'Enabled'
101+
marketplacePlanId: 'enterprise-plan-123'
102+
}
103+
}
104+
sku: {
105+
name: 'Enterprise'
106+
}
107+
}
108+
109+
// Grafana with security settings
110+
resource securityGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
111+
name: 'security-grafana'
112+
location: 'uksouth'
113+
properties: {
114+
grafanaConfigurations: {
115+
security: {
116+
csrfAlwaysCheck: true
117+
}
118+
}
119+
}
120+
sku: {
121+
name: 'Standard'
122+
}
123+
}
124+
125+
// Grafana with SMTP configuration
126+
resource smtpGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
127+
name: 'smtp-grafana'
128+
location: 'japaneast'
129+
properties: {
130+
grafanaConfigurations: {
131+
smtp: {
132+
enabled: true
133+
fromAddress: 'grafana@example.com'
134+
fromName: 'Grafana Alerts'
135+
host: 'smtp.example.com:587'
136+
password: 'SecurePasswordHere'
137+
skipVerify: false
138+
startTLSPolicy: 'MandatoryStartTLS'
139+
user: 'grafanauser'
140+
}
141+
}
142+
}
143+
sku: {
144+
name: 'Standard'
145+
}
146+
}
147+
148+
// Grafana with snapshots configuration
149+
resource snapshotsGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
150+
name: 'snapshots-grafana'
151+
location: 'brazilsouth'
152+
properties: {
153+
grafanaConfigurations: {
154+
snapshots: {
155+
externalEnabled: false
156+
}
157+
}
158+
}
159+
sku: {
160+
name: 'Standard'
161+
}
162+
}
163+
164+
// Grafana with unified alerting screenshots configuration
165+
resource alertingGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
166+
name: 'alerting-grafana'
167+
location: 'australiaeast'
168+
properties: {
169+
grafanaConfigurations: {
170+
unifiedAlertingScreenshots: {
171+
captureEnabled: false
172+
}
173+
}
174+
}
175+
sku: {
176+
name: 'Standard'
177+
}
178+
}
179+
180+
// Grafana with users configuration
181+
resource usersGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
182+
name: 'users-grafana'
183+
location: 'southcentralus'
184+
properties: {
185+
grafanaConfigurations: {
186+
users: {
187+
editorsCanAdmin: true
188+
viewersCanEdit: true
189+
}
190+
}
191+
}
192+
sku: {
193+
name: 'Standard'
194+
}
195+
}
196+
197+
// Grafana with integrations configuration
198+
resource integrationsGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
199+
name: 'integrations-grafana'
200+
location: 'eastus2'
201+
properties: {
202+
grafanaIntegrations: {
203+
azureMonitorWorkspaceIntegrations: [
204+
{
205+
azureMonitorWorkspaceResourceId: '/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.OperationalInsights/workspaces/my-workspace'
206+
},
207+
{
208+
azureMonitorWorkspaceResourceId: '/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.OperationalInsights/workspaces/my-second-workspace'
209+
}
210+
]
211+
}
212+
}
213+
sku: {
214+
name: 'Standard'
215+
}
216+
}
217+
218+
// Grafana with plugins configuration
219+
resource pluginsGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
220+
name: 'plugins-grafana'
221+
location: 'canadacentral'
222+
properties: {
223+
grafanaPlugins: {
224+
'grafana-worldmap-panel': {}
225+
'grafana-piechart-panel': {}
226+
}
227+
}
228+
sku: {
229+
name: 'Standard'
230+
}
231+
}
232+
233+
// Super comprehensive Grafana resource with all properties
234+
resource fullGrafana 'Microsoft.Dashboard/grafana@2024-11-01-preview' = {
235+
name: 'full-featured-grafana'
236+
location: 'westus3'
237+
identity: {
238+
type: 'SystemAssigned,UserAssigned'
239+
userAssignedIdentities: {
240+
'/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-identity': {}
241+
}
242+
}
243+
properties: {
244+
apiKey: 'Enabled'
245+
autoGeneratedDomainNameLabelScope: 'TenantReuse'
246+
deterministicOutboundIP: 'Enabled'
247+
grafanaMajorVersion: '10'
248+
publicNetworkAccess: 'Enabled'
249+
zoneRedundancy: 'Enabled'
250+
enterpriseConfigurations: {
251+
marketplaceAutoRenew: 'Enabled'
252+
marketplacePlanId: 'enterprise-plan-premium'
253+
}
254+
grafanaConfigurations: {
255+
security: {
256+
csrfAlwaysCheck: true
257+
}
258+
smtp: {
259+
enabled: true
260+
fromAddress: 'grafana@company.com'
261+
fromName: 'Grafana Enterprise Alerts'
262+
host: 'smtp.company.com:587'
263+
password: 'SecureEnterprisePassword'
264+
skipVerify: false
265+
startTLSPolicy: 'MandatoryStartTLS'
266+
user: 'grafanaadmin'
267+
}
268+
snapshots: {
269+
externalEnabled: false
270+
}
271+
unifiedAlertingScreenshots: {
272+
captureEnabled: true
273+
}
274+
users: {
275+
editorsCanAdmin: true
276+
viewersCanEdit: false
277+
}
278+
}
279+
grafanaIntegrations: {
280+
azureMonitorWorkspaceIntegrations: [
281+
{
282+
azureMonitorWorkspaceResourceId: '/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.OperationalInsights/workspaces/primary-workspace'
283+
},
284+
{
285+
azureMonitorWorkspaceResourceId: '/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/my-rg/providers/Microsoft.OperationalInsights/workspaces/secondary-workspace'
286+
}
287+
]
288+
}
289+
grafanaPlugins: {
290+
'grafana-worldmap-panel': {}
291+
'grafana-piechart-panel': {}
292+
'grafana-clock-panel': {}
293+
'grafana-azure-monitor-datasource': {}
294+
}
295+
}
296+
sku: {
297+
name: 'Enterprise'
298+
}
299+
tags: {
300+
Environment: 'Production'
301+
Department: 'Engineering'
302+
CostCenter: 'CC-123456'
303+
Project: 'Enterprise Monitoring'
304+
}
305+
}
306+
307+
// Grafana with an older API version
308+
resource olderVersionGrafana 'Microsoft.Dashboard/grafana@2023-09-01' = {
309+
name: 'older-version-grafana'
310+
location: 'eastus'
311+
properties: {
312+
apiKey: 'Enabled'
313+
}
314+
sku: {
315+
name: 'Standard'
316+
}
317+
}

0 commit comments

Comments
 (0)