forked from helderpinto/AzureOptimizationEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredeploy.bicep
1413 lines (1336 loc) · 53.7 KB
/
azuredeploy.bicep
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
param projectLocation string
@description('The base URI where artifacts required by this template are located')
param artifactsLocation string = deployment().properties.templateLink.uri
@description('The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be grabbed from parameters.')
@secure()
param artifactsLocationSasToken string = ''
param storageAccountName string
param automationAccountName string
param sqlServerName string
param sqlDatabaseName string = 'azureoptimization'
param logAnalyticsReuse bool
param logAnalyticsWorkspaceName string
param logAnalyticsWorkspaceRG string
param logAnalyticsRetentionDays int = 120
param sqlBackupRetentionDays int = 7
param sqlAdminLogin string
@secure()
param sqlAdminPassword string
param cloudEnvironment string = 'AzureCloud'
param authenticationOption string = 'RunAsAccount'
@description('Base time for all automation runbook schedules.')
param baseTime string = utcNow('u')
@description('GUID for the ARG Disk Export job schedule creation - create a unique before deploy')
param argDiskExportJobId string = newGuid()
@description('GUID for the ARG VHD Export job schedule creation - create a unique before deploy')
param argVhdExportJobId string = newGuid()
@description('GUID for the ARG VM Export job schedule creation - create a unique before deploy')
param argVmExportJobId string = newGuid()
@description('GUID for the ARG Availability Set Export job schedule creation - create a unique before deploy')
param argAvailSetExportJobId string = newGuid()
@description('GUID for the Advisor Export job schedule creation - create a unique before deploy')
param advisorExportJobId string = newGuid()
@description('GUID for the Consumption Export job schedule creation - create a unique before deploy')
param consumptionExportJobId string = newGuid()
@description('GUID for the Azure AD Objects Export job schedule creation - create a unique before deploy')
param aadObjectsExportJobId string = newGuid()
@description('GUID for the Load Balancers Export job schedule creation - create a unique before deploy')
param argLoadBalancersExportJobId string = newGuid()
@description('GUID for the Application Gateways Export job schedule creation - create a unique before deploy')
param argAppGWsExportJobId string = newGuid()
@description('GUID for the RBAC Export job schedule creation - create a unique before deploy')
param rbacExportJobId string = newGuid()
@description('GUID for the Resource Containers Export job schedule creation - create a unique before deploy')
param argResContainersExportJobId string = newGuid()
@description('GUID for the NIC Export job schedule creation - create a unique before deploy')
param argNICExportJobId string = newGuid()
@description('GUID for the NSG Export job schedule creation - create a unique before deploy')
param argNSGExportJobId string = newGuid()
@description('GUID for the Public IP Export job schedule creation - create a unique before deploy')
param argPublicIPExportJobId string = newGuid()
@description('GUID for the VNet Export job schedule creation - create a unique before deploy')
param argVNetExportJobId string = newGuid()
@description('GUID for the ARG Disk Ingest job schedule creation - create a unique before deploy')
param argDiskIngestJobId string = newGuid()
@description('GUID for the ARG VHD Ingest job schedule creation - create a unique before deploy')
param argVhdIngestJobId string = newGuid()
@description('GUID for the ARG VM Ingest job schedule creation - create a unique before deploy')
param argVmIngestJobId string = newGuid()
@description('GUID for the ARG Availability Set Ingest job schedule creation - create a unique before deploy')
param argAvailSetIngestJobId string = newGuid()
@description('GUID for the Advisor Ingest job schedule creation - create a unique before deploy')
param advisorIngestJobId string = newGuid()
@description('GUID for the Remediation Logs Ingest job schedule creation - create a unique before deploy')
param remediationLogsIngestJobId string = newGuid()
@description('GUID for the Consumption Ingest job schedule creation - create a unique before deploy')
param consumptionIngestJobId string = newGuid()
@description('GUID for the AAD Objects Ingest job schedule creation - create a unique before deploy')
param aadObjectsIngestJobId string = newGuid()
@description('GUID for the Load Balancers Ingest job schedule creation - create a unique before deploy')
param argLoadBalancersIngestJobId string = newGuid()
@description('GUID for the Application Gateways Ingest job schedule creation - create a unique before deploy')
param argAppGWsIngestJobId string = newGuid()
@description('GUID for the Resource Containers Ingest job schedule creation - create a unique before deploy')
param argResContainersIngestJobId string = newGuid()
@description('GUID for the RBAC Ingest job schedule creation - create a unique before deploy')
param rbacIngestJobId string = newGuid()
@description('GUID for the NIC Ingest job schedule creation - create a unique before deploy')
param argNICIngestJobId string = newGuid()
@description('GUID for the NSG Ingest job schedule creation - create a unique before deploy')
param argNSGIngestJobId string = newGuid()
@description('GUID for the Public IP Ingest job schedule creation - create a unique before deploy')
param argPublicIPIngestJobId string = newGuid()
@description('GUID for the VNet Ingest job schedule creation - create a unique before deploy')
param argVNetIngestJobId string = newGuid()
@description('GUID for the Unattached Disks Recommendation Generation job schedule creation - create a unique before deploy')
param unattachedDisksRecommendationJobId string = newGuid()
@description('GUID for the Augmented Advisor Cost Recommendation Generation job schedule creation - create a unique before deploy')
param advisorCostAugmentedRecommendationJobId string = newGuid()
@description('GUID for the Advisor General Recommendations Generation job schedule creation - create a unique before deploy')
param advisorAsIsRecommendationJobId string = newGuid()
@description('GUID for the VMs High Availability Recommendation Generation job schedule creation - create a unique before deploy')
param vmsHaRecommendationJobId string = newGuid()
@description('GUID for the Long Deallocated VMs Recommendation Generation job schedule creation - create a unique before deploy')
param longDeallocatedVmsRecommendationJobId string = newGuid()
@description('GUID for the AAD Objects with Expiring Credentials Recommendation Generation job schedule creation - create a unique before deploy')
param aadExpiringCredsRecommendationJobId string = newGuid()
@description('GUID for the Unused Load Balancers Recommendation Generation job schedule creation - create a unique before deploy')
param unusedLoadBalancersRecommendationJobId string = newGuid()
@description('GUID for the Unused Application Gateways Recommendation Generation job schedule creation - create a unique before deploy')
param unusedAppGWsRecommendationJobId string = newGuid()
@description('GUID for the ARM Optimizations Recommendation Generation job schedule creation - create a unique before deploy')
param armOptimizationsRecommendationJobId string = newGuid()
@description('GUID for the VNet Optimizations Recommendation Generation job schedule creation - create a unique before deploy')
param vnetOptimizationsRecommendationJobId string = newGuid()
@description('GUID for the Recommendations Ingest job schedule creation - create a unique before deploy')
param recommendationsIngestJobId string = newGuid()
var advisorExportsRunbookName = 'Export-AdvisorRecommendationsToBlobStorage'
var argVmExportsRunbookName = 'Export-ARGVirtualMachinesPropertiesToBlobStorage'
var argDisksExportsRunbookName = 'Export-ARGManagedDisksPropertiesToBlobStorage'
var argVhdExportsRunbookName = 'Export-ARGUnmanagedDisksPropertiesToBlobStorage'
var argAvailSetExportsRunbookName = 'Export-ARGAvailabilitySetPropertiesToBlobStorage'
var consumptionExportsRunbookName = 'Export-ConsumptionToBlobStorage'
var aadObjectsExportsRunbookName = 'Export-AADObjectsToBlobStorage'
var argLoadBalancersExportsRunbookName = 'Export-ARGLoadBalancerPropertiesToBlobStorage'
var argAppGWsExportsRunbookName = 'Export-ARGAppGatewayPropertiesToBlobStorage'
var argResContainersExportsRunbookName = 'Export-ARGResourceContainersPropertiesToBlobStorage'
var rbacExportsRunbookName = 'Export-RBACAssignmentsToBlobStorage'
var argNICExportsRunbookName = 'Export-ARGNICPropertiesToBlobStorage'
var argNSGExportsRunbookName = 'Export-ARGNSGPropertiesToBlobStorage'
var argVNetExportsRunbookName = 'Export-ARGVNetPropertiesToBlobStorage'
var argPublicIpExportsRunbookName = 'Export-ARGPublicIpPropertiesToBlobStorage'
var advisorExportsScheduleName = 'AzureOptimization_ExportAdvisorWeekly'
var argExportsScheduleName = 'AzureOptimization_ExportARGDaily'
var consumptionExportsScheduleName = 'AzureOptimization_ExportConsumptionDaily'
var aadObjectsExportsScheduleName = 'AzureOptimization_ExportAADObjectsDaily'
var rbacExportsScheduleName = 'AzureOptimization_ExportRBACDaily'
var csvExportsSchedules = [
{
exportSchedule: argExportsScheduleName
exportDescription: 'Daily Azure Resource Graph exports'
exportTimeOffset: 'PT1H'
exportFrequency: 'Day'
}
{
exportSchedule: advisorExportsScheduleName
exportDescription: 'Weekly Azure Advisor exports'
exportTimeOffset: 'PT1H15M'
exportFrequency: 'Week'
}
{
exportSchedule: consumptionExportsScheduleName
exportDescription: 'Daily Azure Consumption exports'
exportTimeOffset: 'PT1H'
exportFrequency: 'Day'
}
{
exportSchedule: aadObjectsExportsScheduleName
exportDescription: 'Daily Azure AD Objects exports'
exportTimeOffset: 'PT1H'
exportFrequency: 'Day'
}
{
exportSchedule: rbacExportsScheduleName
exportDescription: 'Daily Azure RBAC exports'
exportTimeOffset: 'PT1H'
exportFrequency: 'Day'
}
]
var csvExports = [
{
runbookName: advisorExportsRunbookName
containerName: 'advisorexports'
variableName: 'AzureOptimization_AdvisorContainer'
variableDescription: 'The Storage Account container where Azure Advisor exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestAdvisorWeekly'
ingestDescription: 'Weekly Azure Advisor recommendations ingests'
ingestTimeOffset: 'PT1H45M'
ingestFrequency: 'Week'
ingestJobId: advisorIngestJobId
exportSchedule: advisorExportsScheduleName
exportJobId: advisorExportJobId
}
{
runbookName: argVmExportsRunbookName
containerName: 'argvmexports'
variableName: 'AzureOptimization_ARGVMContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Virtual Machine exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGVMsDaily'
ingestDescription: 'Daily Azure Resource Graph Virtual Machines ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argVmIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argVmExportJobId
}
{
runbookName: argDisksExportsRunbookName
containerName: 'argdiskexports'
variableName: 'AzureOptimization_ARGDiskContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Managed Disks exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGDisksDaily'
ingestDescription: 'Daily Azure Resource Graph Managed Disks ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argDiskIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argDiskExportJobId
}
{
runbookName: argVhdExportsRunbookName
containerName: 'argvhdexports'
variableName: 'AzureOptimization_ARGVhdContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Unmanaged Disks exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGVHDsDaily'
ingestDescription: 'Daily Azure Resource Graph Unmanaged Disks ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argVhdIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argVhdExportJobId
}
{
runbookName: argAvailSetExportsRunbookName
containerName: 'argavailsetexports'
variableName: 'AzureOptimization_ARGAvailabilitySetContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Availability Set exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGAvailSetsDaily'
ingestDescription: 'Daily Azure Resource Graph Availability Sets ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argAvailSetIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argAvailSetExportJobId
}
{
runbookName: consumptionExportsRunbookName
containerName: 'consumptionexports'
variableName: 'AzureOptimization_ConsumptionContainer'
variableDescription: 'The Storage Account container where Azure Consumption exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestConsumptionDaily'
ingestDescription: 'Daily Azure Consumption ingests'
ingestTimeOffset: 'PT2H'
ingestFrequency: 'Day'
ingestJobId: consumptionIngestJobId
exportSchedule: consumptionExportsScheduleName
exportJobId: consumptionExportJobId
}
{
runbookName: aadObjectsExportsRunbookName
containerName: 'aadobjectsexports'
variableName: 'AzureOptimization_AADObjectsContainer'
variableDescription: 'The Storage Account container where Azure AD Objects exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestAADObjectsDaily'
ingestDescription: 'Daily Azure AD Objects ingests'
ingestTimeOffset: 'PT2H'
ingestFrequency: 'Day'
ingestJobId: aadObjectsIngestJobId
exportSchedule: aadObjectsExportsScheduleName
exportJobId: aadObjectsExportJobId
}
{
runbookName: argLoadBalancersExportsRunbookName
containerName: 'arglbexports'
variableName: 'AzureOptimization_ARGLoadBalancerContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Load Balancer exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGLoadBalancersDaily'
ingestDescription: 'Daily Azure Resource Graph Load Balancers ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argLoadBalancersIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argLoadBalancersExportJobId
}
{
runbookName: argAppGWsExportsRunbookName
containerName: 'argappgwexports'
variableName: 'AzureOptimization_ARGAppGatewayContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Application Gateway exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGAppGWsDaily'
ingestDescription: 'Daily Azure Resource Graph Application Gateways ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argAppGWsIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argAppGWsExportJobId
}
{
runbookName: argResContainersExportsRunbookName
containerName: 'argrescontainersexports'
variableName: 'AzureOptimization_ARGResourceContainersContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Resource Containers exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGResourceContainersDaily'
ingestDescription: 'Daily Azure Resource Graph Resource Containers ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argResContainersIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argResContainersExportJobId
}
{
runbookName: rbacExportsRunbookName
containerName: 'rbacexports'
variableName: 'AzureOptimization_RBACAssignmentsContainer'
variableDescription: 'The Storage Account container where RBAC Assignments exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestRBACDaily'
ingestDescription: 'Daily Azure RBAC ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: rbacIngestJobId
exportSchedule: rbacExportsScheduleName
exportJobId: rbacExportJobId
}
{
runbookName: argNICExportsRunbookName
containerName: 'argnicexports'
variableName: 'AzureOptimization_ARGNICContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph NIC exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGNICsDaily'
ingestDescription: 'Daily Azure Resource Graph NIC ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argNICIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argNICExportJobId
}
{
runbookName: argNSGExportsRunbookName
containerName: 'argnsgexports'
variableName: 'AzureOptimization_ARGNSGContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph NSG exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGNSGsDaily'
ingestDescription: 'Daily Azure Resource Graph NSG ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argNSGIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argNSGExportJobId
}
{
runbookName: argVNetExportsRunbookName
containerName: 'argvnetexports'
variableName: 'AzureOptimization_ARGVNetContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph VNet exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGVNetsDaily'
ingestDescription: 'Daily Azure Resource Graph Virtual Network ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argVNetIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argVNetExportJobId
}
{
runbookName: argPublicIpExportsRunbookName
containerName: 'argpublicipexports'
variableName: 'AzureOptimization_ARGPublicIpContainer'
variableDescription: 'The Storage Account container where Azure Resource Graph Public IP exports are dumped to'
ingestSchedule: 'AzureOptimization_IngestARGPublicIPsDaily'
ingestDescription: 'Daily Azure Resource Graph Public IP ingests'
ingestTimeOffset: 'PT1H30M'
ingestFrequency: 'Day'
ingestJobId: argPublicIPIngestJobId
exportSchedule: argExportsScheduleName
exportJobId: argPublicIPExportJobId
}
]
var unattachedDisksRecommendationsRunbookName = 'Recommend-UnattachedDisksToBlobStorage'
var advisorCostAugmentedRecommendationsRunbookName = 'Recommend-AdvisorCostAugmentedToBlobStorage'
var advisorAsIsRecommendationsRunbookName = 'Recommend-AdvisorAsIsToBlobStorage'
var vmsHARecommendationsRunbookName = 'Recommend-VMsHighAvailabilityToBlobStorage'
var longDeallocatedVmsRecommendationsRunbookName = 'Recommend-LongDeallocatedVmsToBlobStorage'
var aadExpiringCredsRecommendationsRunbookName = 'Recommend-AADExpiringCredentialsToBlobStorage'
var unusedLBsRecommendationsRunbookName = 'Recommend-UnusedLoadBalancersToBlobStorage'
var unusedAppGWsRecommendationsRunbookName = 'Recommend-UnusedAppGWsToBlobStorage'
var armOptimizationsRecommendationsRunbookName = 'Recommend-ARMOptimizationsToBlobStorage'
var vnetOptimizationsRecommendationsRunbookName = 'Recommend-VNetOptimizationsToBlobStorage'
var recommendations = [
{
recommendationJobId: unattachedDisksRecommendationJobId
runbookName: unattachedDisksRecommendationsRunbookName
}
{
recommendationJobId: advisorCostAugmentedRecommendationJobId
runbookName: advisorCostAugmentedRecommendationsRunbookName
}
{
recommendationJobId: advisorAsIsRecommendationJobId
runbookName: advisorAsIsRecommendationsRunbookName
}
{
recommendationJobId: vmsHaRecommendationJobId
runbookName: vmsHARecommendationsRunbookName
}
{
recommendationJobId: longDeallocatedVmsRecommendationJobId
runbookName: longDeallocatedVmsRecommendationsRunbookName
}
{
recommendationJobId: aadExpiringCredsRecommendationJobId
runbookName: aadExpiringCredsRecommendationsRunbookName
}
{
recommendationJobId: unusedLoadBalancersRecommendationJobId
runbookName: unusedLBsRecommendationsRunbookName
}
{
recommendationJobId: unusedAppGWsRecommendationJobId
runbookName: unusedAppGWsRecommendationsRunbookName
}
{
recommendationJobId: armOptimizationsRecommendationJobId
runbookName: armOptimizationsRecommendationsRunbookName
}
{
recommendationJobId: vnetOptimizationsRecommendationJobId
runbookName: vnetOptimizationsRecommendationsRunbookName
}
]
var remediationLogsContainerName = 'remediationlogs'
var recommendationsContainerName = 'recommendationsexports'
var csvIngestRunbookName = 'Ingest-OptimizationCSVExportsToLogAnalytics'
var recommendationsIngestRunbookName = 'Ingest-RecommendationsToSQLServer'
var advisorRightSizeFilteredRemediationRunbookName = 'Remediate-AdvisorRightSizeFiltered'
var longDeallocatedVMsFilteredRemediationRunbookName = 'Remediate-LongDeallocatedVMsFiltered'
var unattachedDisksFilteredRemediationRunbookName = 'Remediate-UnattachedDisksFiltered'
var remediationLogsIngestScheduleName = 'AzureOptimization_IngestRemediationLogsDaily'
var recommendationsScheduleName = 'AzureOptimization_RecommendationsWeekly'
var recommendationsIngestScheduleName = 'AzureOptimization_IngestRecommendationsWeekly'
var apiVersions = {
operationalInsights: '2020-08-01'
automation: '2018-06-30'
storage: '2019-06-01'
sql: '2019-06-01-preview'
}
var Az_Accounts = {
name: 'Az.Accounts'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Accounts/2.5.2'
}
var psModules = [
{
name: 'Az.Advisor'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Advisor/1.1.1'
}
{
name: 'Az.Billing'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Billing/2.0.0'
}
{
name: 'Az.Compute'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Compute/4.16.0'
}
{
name: 'Az.OperationalInsights'
url: 'https://www.powershellgallery.com/api/v2/package/Az.OperationalInsights/2.3.0'
}
{
name: 'Az.ResourceGraph'
url: 'https://www.powershellgallery.com/api/v2/package/Az.ResourceGraph/0.11.0'
}
{
name: 'Az.Storage'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Storage/3.10.0'
}
{
name: 'Az.Resources'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Resources/4.3.0'
}
{
name: 'Az.Monitor'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Monitor/2.7.0'
}
{
name: 'AzureADPreview'
url: 'https://www.powershellgallery.com/api/v2/package/AzureADPreview/2.0.2.138'
}
]
var runbooks = [
{
name: advisorExportsRunbookName
version: '1.3.0.0'
description: 'Exports Azure Advisor recommendations to Blob Storage using the Advisor API'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${advisorExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argDisksExportsRunbookName
version: '1.3.2.0'
description: 'Exports Managed Disks properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argDisksExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argVhdExportsRunbookName
version: '1.1.2.0'
description: 'Exports Unmanaged Disks (owned by a VM) properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argVhdExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argVmExportsRunbookName
version: '1.4.2.0'
description: 'Exports Virtual Machine properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argVmExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argAvailSetExportsRunbookName
version: '1.1.2.0'
description: 'Exports Availability Set properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argAvailSetExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: consumptionExportsRunbookName
version: '1.1.1.0'
description: 'Exports Azure Consumption events to Blob Storage using Azure Consumption API'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${consumptionExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: aadObjectsExportsRunbookName
version: '1.1.2.0'
description: 'Exports Azure AAD Objects to Blob Storage using Azure ARM API'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${aadObjectsExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argLoadBalancersExportsRunbookName
version: '1.1.2.0'
description: 'Exports Load Balancer properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argLoadBalancersExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argAppGWsExportsRunbookName
version: '1.1.2.0'
description: 'Exports Application Gateway properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argAppGWsExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argResContainersExportsRunbookName
version: '1.0.2.0'
description: 'Exports Resource Containers properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argResContainersExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: rbacExportsRunbookName
version: '1.0.0.0'
description: 'Exports RBAC assignments to Blob Storage using ARM and Azure AD'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${rbacExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argNICExportsRunbookName
version: '1.0.0.0'
description: 'Exports NIC properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argNICExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argNSGExportsRunbookName
version: '1.0.0.0'
description: 'Exports NSG properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argNSGExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argPublicIpExportsRunbookName
version: '1.0.0.0'
description: 'Exports Public IP properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argPublicIpExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: argVNetExportsRunbookName
version: '1.0.0.0'
description: 'Exports VNet properties to Blob Storage using Azure Resource Graph'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${argVNetExportsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: csvIngestRunbookName
version: '1.4.4.0'
description: 'Ingests CSV blobs as custom logs to Log Analytics'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/data-collection/${csvIngestRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unattachedDisksRecommendationsRunbookName
version: '2.4.4.0'
description: 'Generates unattached disks recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unattachedDisksRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: advisorCostAugmentedRecommendationsRunbookName
version: '2.8.3.0'
description: 'Generates augmented Advisor Cost recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${advisorCostAugmentedRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: advisorAsIsRecommendationsRunbookName
version: '1.5.3.0'
description: 'Generates all types of Advisor recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${advisorAsIsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: vmsHARecommendationsRunbookName
version: '1.0.0.0'
description: 'Generates VMs High Availability recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${vmsHARecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: longDeallocatedVmsRecommendationsRunbookName
version: '1.2.3.0'
description: 'Generates long deallocated VMs recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${longDeallocatedVmsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: aadExpiringCredsRecommendationsRunbookName
version: '1.1.8.0'
description: 'Generates AAD Objects with expiring credentials recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${aadExpiringCredsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unusedLBsRecommendationsRunbookName
version: '1.2.5.0'
description: 'Generates unused Load Balancers recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unusedLBsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unusedAppGWsRecommendationsRunbookName
version: '1.2.4.0'
description: 'Generates unused Application Gateways recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unusedAppGWsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: armOptimizationsRecommendationsRunbookName
version: '1.0.1.0'
description: 'Generates ARM optimizations recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${armOptimizationsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: vnetOptimizationsRecommendationsRunbookName
version: '1.0.0.0'
description: 'Generates Virtual Network optimizations recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${vnetOptimizationsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: recommendationsIngestRunbookName
version: '1.6.1.0'
description: 'Ingests JSON-based recommendations into an Azure SQL Database'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${recommendationsIngestRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: advisorRightSizeFilteredRemediationRunbookName
version: '1.2.1.0'
description: 'Remediates Azure Advisor right-size recommendations given fit and tag filters'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/remediations/${advisorRightSizeFilteredRemediationRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: longDeallocatedVMsFilteredRemediationRunbookName
version: '1.0.0.0'
description: 'Remediates long-deallocated VMs recommendations given fit and tag filters'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/remediations/${longDeallocatedVMsFilteredRemediationRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unattachedDisksFilteredRemediationRunbookName
version: '1.0.0.0'
description: 'Remediates unattached disks recommendations given fit and tag filters'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/remediations/${unattachedDisksFilteredRemediationRunbookName}.ps1${artifactsLocationSasToken}')
}
]
var automationVariables = [
{
name: 'AzureOptimization_CloudEnvironment'
description: 'Azure Cloud environment (e.g., AzureCloud, AzureChinaCloud, etc.)'
value: '"${cloudEnvironment}"'
}
{
name: 'AzureOptimization_AuthenticationOption'
description: 'Runbook authentication type (Run As Account or Managed Identity)'
value: '"${authenticationOption}"'
}
{
name: 'AzureOptimization_StorageSink'
description: 'The Azure Storage Account where data source exports are dumped to'
value: '"${storageAccountName}"'
}
{
name: 'AzureOptimization_StorageSinkRG'
description: 'The resource group for the Azure Storage Account sink'
value: '"${resourceGroup().name}"'
}
{
name: 'AzureOptimization_StorageSinkSubId'
description: 'The subscription Id for the Azure Storage Account sink'
value: '"${subscription().subscriptionId}"'
}
{
name: 'AzureOptimization_ConsumptionOffsetDays'
description: 'The offset (in days) for querying for consumption data'
value: 3
}
{
name: 'AzureOptimization_AdvisorFilter'
description: 'The category filter to use for Azure Advisor (non-Cost) recommendations exports'
value: '"HighAvailability,Security,Performance,OperationalExcellence"'
}
{
name: 'AzureOptimization_ReferenceRegion'
description: 'The Azure region used as a reference for getting details about Azure VM sizes available'
value: '"${projectLocation}"'
}
{
name: 'AzureOptimization_SQLServerDatabase'
description: 'The Azure SQL Database name for the ingestion control and recommendations tables'
value: '"${sqlDatabaseName}"'
}
{
name: 'AzureOptimization_LogAnalyticsChunkSize'
description: 'The size (in rows) for each chunk of Log Analytics ingestion request'
value: 9000
}
{
name: 'AzureOptimization_StorageBlobsPageSize'
description: 'The size (in blobs count) for each page of Storage Account container blob listing'
value: 1000
}
{
name: 'AzureOptimization_SQLServerInsertSize'
description: 'The size (in inserted lines) for each page of recommendations ingestion into the SQL Database'
value: 900
}
{
name: 'AzureOptimization_LogAnalyticsLogPrefix'
description: 'The prefix for all Azure Optimization custom log tables in Log Analytics'
value: '"AzureOptimization"'
}
{
name: 'AzureOptimization_LogAnalyticsWorkspaceName'
description: 'The Log Analytics Workspace Name where optimization data will be ingested'
value: '"${logAnalyticsWorkspaceName}"'
}
{
name: 'AzureOptimization_LogAnalyticsWorkspaceRG'
description: 'The resource group for the Log Analytics Workspace where optimization data will be ingested'
value: '"${((!logAnalyticsReuse) ? resourceGroup().name : logAnalyticsWorkspaceRG)}"'
}
{
name: 'AzureOptimization_LogAnalyticsWorkspaceSubId'
description: 'The Azure subscription for the Log Analytics Workspace where optimization data will be ingested'
value: '"${subscription().subscriptionId}"'
}
{
name: 'AzureOptimization_LogAnalyticsWorkspaceTenantId'
description: 'The Azure AD tenant for the Log Analytics Workspace where optimization data will be ingested'
value: '"${subscription().tenantId}"'
}
{
name: 'AzureOptimization_RecommendAdvisorPeriodInDays'
description: 'The period (in days) to look back for Advisor exported recommendations'
value: 7
}
{
name: 'AzureOptimization_RecommendationLongDeallocatedVmsIntervalDays'
description: 'The period (in days) for considering a VM long deallocated'
value: 30
}
{
name: 'AzureOptimization_PerfPercentileCpu'
description: 'The percentile to be used for processor metrics'
value: 99
}
{
name: 'AzureOptimization_PerfPercentileMemory'
description: 'The percentile to be used for memory metrics'
value: 99
}
{
name: 'AzureOptimization_PerfPercentileNetwork'
description: 'The percentile to be used for network metrics'
value: 99
}
{
name: 'AzureOptimization_PerfPercentileDisk'
description: 'The percentile to be used for disk metrics'
value: 99
}
{
name: 'AzureOptimization_PerfThresholdCpuPercentage'
description: 'The processor usage percentage threshold above which the fit score is decreased'
value: 30
}
{
name: 'AzureOptimization_PerfThresholdMemoryPercentage'
description: 'The memory usage percentage threshold above which the fit score is decreased'
value: 50
}
{
name: 'AzureOptimization_PerfThresholdNetworkMbps'
description: 'The network usage threshold (in Mbps) above which the fit score is decreased'
value: 750
}
{
name: 'AzureOptimization_PerfThresholdCpuShutdownPercentage'
description: 'The processor usage percentage threshold above which the fit score is decreased (shutdown scenarios)'
value: 5
}
{
name: 'AzureOptimization_PerfThresholdMemoryShutdownPercentage'
description: 'The memory usage percentage threshold above which the fit score is decreased (shutdown scenarios)'
value: 100
}
{
name: 'AzureOptimization_PerfThresholdNetworkShutdownMbps'
description: 'The network usage threshold (in Mbps) above which the fit score is decreased (shutdown scenarios)'
value: 10
}
{
name: 'AzureOptimization_RemediateRightSizeMinFitScore'
description: 'The minimum fit score for right-size remediation'
value: '"5.0"'
}
{
name: 'AzureOptimization_RemediateRightSizeMinWeeksInARow'
description: 'The minimum number of weeks in a row required for a right-size recommendation to be remediated'
value: 4
}
{
name: 'AzureOptimization_RecommendationAdvisorCostRightSizeId'
description: 'The Azure Advisor VM right-size recommendation ID'
value: '"e10b1381-5f0a-47ff-8c7b-37bd13d7c974"'
}
{
name: 'AzureOptimization_RemediateLongDeallocatedVMsMinFitScore'
description: 'The minimum fit score for long-deallocated VM remediation'
value: '"5.0"'
}
{
name: 'AzureOptimization_RemediateLongDeallocatedVMsMinWeeksInARow'
description: 'The minimum number of weeks in a row required for a long-deallocated VM recommendation to be remediated'
value: 4
}
{
name: 'AzureOptimization_RecommendationLongDeallocatedVMsId'
description: 'The long deallocated VM recommendation ID'
value: '"c320b790-2e58-452a-aa63-7b62c383ad8a"'
}
{
name: 'AzureOptimization_RemediateUnattachedDisksMinFitScore'
description: 'The minimum fit score for unattached disk remediation'
value: '"5.0"'
}
{
name: 'AzureOptimization_RemediateUnattachedDisksMinWeeksInARow'
description: 'The minimum number of weeks in a row required for a unattached disk recommendation to be remediated'
value: 4
}
{
name: 'AzureOptimization_RemediateUnattachedDisksAction'
description: 'The action for the unattached disk recommendation to be remediated (Delete or Downsize)'
value: '"Delete"'
}
{
name: 'AzureOptimization_RecommendationUnattachedDisksId'
description: 'The unattached disk recommendation ID'
value: '"c84d5e86-e2d6-4d62-be7c-cecfbd73b0db"'
}
{
name: 'AzureOptimization_RecommendationAADMinCredValidityDays'
description: 'The minimum validity of an AAD Object credential in days'
value: 30
}
{
name: 'AzureOptimization_RecommendationAADMaxCredValidityYears'
description: 'The maximum validity of an AAD Object credential in years'
value: 2
}
{
name: 'AzureOptimization_AADObjectsFilter'
description: 'The Azure AD object types to export'
value: '"Application,ServicePrincipal,User,Group"'
}
{
name: 'AzureOptimization_RecommendationRBACAssignmentsPercentageThreshold'
description: 'The percentage threshold (used to trigger recommendations) for total RBAC assignments limits'
value: 80
}
{
name: 'AzureOptimization_RecommendationResourceGroupsPerSubPercentageThreshold'
description: 'The percentage threshold (used to trigger recommendations) for resource group count limits'
value: 80
}
{
name: 'AzureOptimization_RecommendationVNetSubnetMaxUsedPercentageThreshold'
description: 'The percentage threshold (used to trigger recommendations) for maximum subnet address space usage'
value: 80
}
{
name: 'AzureOptimization_RecommendationVNetSubnetMinUsedPercentageThreshold'
description: 'The percentage threshold (used to trigger recommendations) for minimum subnet address space usage'
value: 5
}
{
name: 'AzureOptimization_RecommendationVNetSubnetEmptyMinAgeInDays'
description: 'The minimum age (in days) for an empty subnet to trigger an NSG rule recommendation'
value: 30
}
]
resource logAnalyticsWorkspaceName_resource 'microsoft.operationalinsights/workspaces@2020-08-01' = if (!logAnalyticsReuse) {
name: logAnalyticsWorkspaceName
location: projectLocation
properties: {
sku: {
name: 'pergb2018'
}
retentionInDays: logAnalyticsRetentionDays
}
}
resource storageAccountName_resource 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
location: projectLocation
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
networkAcls: {
bypass: 'AzureServices'
virtualNetworkRules: []
ipRules: []
defaultAction: 'Allow'
}
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
enabled: true
}
blob: {
enabled: true
}
}
keySource: 'Microsoft.Storage'
}