forked from helderpinto/AzureOptimizationEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazuredeploy.bicep
2127 lines (1997 loc) · 73 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 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 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 Unmanaged Disks Recommendation Generation job schedule creation - create a unique before deploy')
param unmanagedDisksRecommendationJobId string = newGuid()
@description('GUID for the Availability Sets with Low Fault Domains Recommendation Generation job schedule creation - create a unique before deploy')
param availSetsLowFaultDomainRecommendationJobId string = newGuid()
@description('GUID for the Availability Sets with Low Update Domains Recommendation Generation job schedule creation - create a unique before deploy')
param availSetsLowUpdateDomainRecommendationJobId string = newGuid()
@description('GUID for the Availability Sets with VMs Sharing Storage Recommendation Generation job schedule creation - create a unique before deploy')
param availSetsSharingStorageRecommendationJobId 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 Storage Accounts with Multiple VMs Recommendation Generation job schedule creation - create a unique before deploy')
param storageAccountsMultipleVmsRecommendationJobId string = newGuid()
@description('GUID for the VMs without Availability Set Recommendation Generation job schedule creation - create a unique before deploy')
param vmsNoAvailSetRecommendationJobId string = newGuid()
@description('GUID for the VMs single in Availability Set Recommendation Generation job schedule creation - create a unique before deploy')
param vmsSingleInAvailSetRecommendationJobId string = newGuid()
@description('GUID for the VMs with Disks in Multiple Storage Accounts Recommendation Generation job schedule creation - create a unique before deploy')
param vmsDisksMultipleStorageRecommendationJobId 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 Recommendations Ingest job schedule creation - create a unique before deploy')
param recommendationsIngestJobId string = newGuid()
var advisorContainerName = 'advisorexports'
var argVmContainerName = 'argvmexports'
var argDiskContainerName = 'argdiskexports'
var argVhdContainerName = 'argvhdexports'
var argAvailSetContainerName = 'argavailsetexports'
var consumptionContainerName = 'consumptionexports'
var recommendationsContainerName = 'recommendationsexports'
var aadObjectsContainerName = 'aadobjectsexports'
var argLBsContainerName = 'arglbexports'
var argAppGWsContainerName = 'argappgwexports'
var argResContainersContainerName = 'argrescontainersexports'
var rbacContainerName = 'rbacexports'
var remediationLogsContainerName = 'remediationlogs'
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 csvIngestRunbookName = 'Ingest-OptimizationCSVExportsToLogAnalytics'
var unattachedDisksRecommendationsRunbookName = 'Recommend-UnattachedDisksToBlobStorage'
var advisorCostAugmentedRecommendationsRunbookName = 'Recommend-AdvisorCostAugmentedToBlobStorage'
var advisorAsIsRecommendationsRunbookName = 'Recommend-AdvisorAsIsToBlobStorage'
var unmanagedDisksRecommendationsRunbookName = 'Recommend-VMsWithUnmanagedDisksToBlobStorage'
var availSetsLowFaultDomainRecommendationsRunbookName = 'Recommend-AvailSetsWithLowFaultDomainCountToBlobStorage'
var availSetsLowUpdateDomainRecommendationsRunbookName = 'Recommend-AvailSetsWithLowUpdateDomainCountToBlobStorage'
var availSetsSharingStorageRecommendationsRunbookName = 'Recommend-AvailSetsWithVMsSharingStorageAccountsToBlobStorage'
var longDeallocatedVmsRecommendationsRunbookName = 'Recommend-LongDeallocatedVmsToBlobStorage'
var storageAccountsMultipleVmsRecommendationsRunbookName = 'Recommend-StorageAccountsWithMultipleVMsToBlobStorage'
var vmsNoAvailSetRecommendationsRunbookName = 'Recommend-VMsNoAvailSetToBlobStorage'
var vmsSingleInAvailSetRecommendationsRunbookName = 'Recommend-VMsSingleInAvailSetToBlobStorage'
var vmsDisksMultipleStorageRecommendationsRunbookName = 'Recommend-VMsWithDisksMultipleStorageAccountsToBlobStorage'
var aadExpiringCredsRecommendationsRunbookName = 'Recommend-AADExpiringCredentialsToBlobStorage'
var unusedLBsRecommendationsRunbookName = 'Recommend-UnusedLoadBalancersToBlobStorage'
var unusedAppGWsRecommendationsRunbookName = 'Recommend-UnusedAppGWsToBlobStorage'
var recommendationsIngestRunbookName = 'Ingest-RecommendationsToSQLServer'
var advisorRightSizeFilteredRemediationRunbookName = 'Remediate-AdvisorRightSizeFiltered'
var advisorExportsScheduleName = 'AzureOptimization_ExportAdvisorWeekly'
var argExportsScheduleName = 'AzureOptimization_ExportARGDaily'
var consumptionExportsScheduleName = 'AzureOptimization_ExportConsumptionDaily'
var aadObjectsExportsScheduleName = 'AzureOptimization_ExportAADObjectsDaily'
var argDiskIngestScheduleName = 'AzureOptimization_IngestARGDisksDaily'
var argVhdIngestScheduleName = 'AzureOptimization_IngestARGVHDsDaily'
var argVmIngestScheduleName = 'AzureOptimization_IngestARGVMsDaily'
var argAvailSetIngestScheduleName = 'AzureOptimization_IngestARGAvailSetsDaily'
var remediationLogsIngestScheduleName = 'AzureOptimization_IngestRemediationLogsDaily'
var consumptionIngestScheduleName = 'AzureOptimization_IngestConsumptionDaily'
var aadObjectsIngestScheduleName = 'AzureOptimization_IngestAADObjectsDaily'
var argLBsIngestScheduleName = 'AzureOptimization_IngestARGLoadBalancersDaily'
var argAppGWsIngestScheduleName = 'AzureOptimization_IngestARGAppGWsDaily'
var argResContainersIngestScheduleName = 'AzureOptimization_IngestARGResourceContainersDaily'
var rbacIngestScheduleName = 'AzureOptimization_IngestRBACAssignmentsDaily'
var advisorIngestScheduleName = 'AzureOptimization_IngestAdvisorWeekly'
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.2.4'
}
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.8.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.8.0'
}
{
name: 'Az.Storage'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Storage/3.2.1'
}
{
name: 'Az.Resources'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Resources/3.2.0'
}
{
name: 'Az.Monitor'
url: 'https://www.powershellgallery.com/api/v2/package/Az.Monitor/2.4.0'
}
{
name: 'AzureADPreview'
url: 'https://www.powershellgallery.com/api/v2/package/AzureADPreview/2.0.2.129'
}
]
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.0.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.0.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.0.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.0.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.0.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.1.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.0.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.0.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.0.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: csvIngestRunbookName
version: '1.4.3.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.1.0'
description: 'Generates unattached disks recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unattachedDisksRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: advisorCostAugmentedRecommendationsRunbookName
version: '2.8.1.0'
description: 'Generates augmented Advisor Cost recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${advisorCostAugmentedRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: advisorAsIsRecommendationsRunbookName
version: '1.5.1.0'
description: 'Generates all types of Advisor recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${advisorAsIsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unmanagedDisksRecommendationsRunbookName
version: '1.5.1.0'
description: 'Generates unmanaged disks recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unmanagedDisksRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: availSetsLowFaultDomainRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates low fault domain Availability Set recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${availSetsLowFaultDomainRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: availSetsLowUpdateDomainRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates low update domain Availability Set recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${availSetsLowUpdateDomainRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: availSetsSharingStorageRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates Availability Set VMs sharing storage recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${availSetsSharingStorageRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: longDeallocatedVmsRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates long deallocated VMs recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${longDeallocatedVmsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: storageAccountsMultipleVmsRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates storage accounts with multiple VMs recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${storageAccountsMultipleVmsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: vmsNoAvailSetRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates VMs without Availability Set recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${vmsNoAvailSetRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: vmsSingleInAvailSetRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates VMs single in Availability Set recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${vmsSingleInAvailSetRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: vmsDisksMultipleStorageRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates VMs with disks in multiple storage accounts recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${vmsDisksMultipleStorageRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: aadExpiringCredsRecommendationsRunbookName
version: '1.1.6.0'
description: 'Generates AAD Objects with expiring credentials recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${aadExpiringCredsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unusedLBsRecommendationsRunbookName
version: '1.2.2.0'
description: 'Generates unused Load Balancers recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unusedLBsRecommendationsRunbookName}.ps1${artifactsLocationSasToken}')
}
{
name: unusedAppGWsRecommendationsRunbookName
version: '1.2.1.0'
description: 'Generates unused Application Gateways recommendations'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/recommendations/${unusedAppGWsRecommendationsRunbookName}.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.0.0'
description: 'Remediates Azure Advisor right-size recommendations given fit and tag filters'
type: 'PowerShell'
scriptUri: uri(artifactsLocation, 'runbooks/remediations/${advisorRightSizeFilteredRemediationRunbookName}.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_AdvisorContainer'
description: 'The Storage Account container where Azure Advisor exports are dumped to'
value: '"${advisorContainerName}"'
}
{
name: 'AzureOptimization_ARGDiskContainer'
description: 'The Storage Account container where Azure Resource Graph Managed Disks exports are dumped to'
value: '"${argDiskContainerName}"'
}
{
name: 'AzureOptimization_ARGVhdContainer'
description: 'The Storage Account container where Azure Resource Graph Unmanaged Disks exports are dumped to'
value: '"${argVhdContainerName}"'
}
{
name: 'AzureOptimization_ARGVMContainer'
description: 'The Storage Account container where Azure Resource Graph Virtual Machine exports are dumped to'
value: '"${argVmContainerName}"'
}
{
name: 'AzureOptimization_ARGAvailabilitySetContainer'
description: 'The Storage Account container where Azure Resource Graph Availability Set exports are dumped to'
value: '"${argAvailSetContainerName}"'
}
{
name: 'AzureOptimization_ConsumptionContainer'
description: 'The Storage Account container where Azure Consumption exports are dumped to'
value: '"${consumptionContainerName}"'
}
{
name: 'AzureOptimization_AADObjectsContainer'
description: 'The Storage Account container where Azure AD Objects exports are dumped to'
value: '"${aadObjectsContainerName}"'
}
{
name: 'AzureOptimization_ARGLoadBalancerContainer'
description: 'The Storage Account container where Azure Resource Graph Load Balancer exports are dumped to'
value: '"${argLBsContainerName}"'
}
{
name: 'AzureOptimization_ARGAppGatewayContainer'
description: 'The Storage Account container where Azure Resource Graph Application Gateway exports are dumped to'
value: '"${argAppGWsContainerName}"'
}
{
name: 'AzureOptimization_ARGResourceContainersContainer'
description: 'The Storage Account container where Azure Resource Graph Resource Containers exports are dumped to'
value: '"${argResContainersContainerName}"'
}
{
name: 'AzureOptimization_RBACAssignmentsContainer'
description: 'The Storage Account container where RBAC Assignments exports are dumped to'
value: '"${rbacContainerName}"'
}
{
name: 'AzureOptimization_ConsumptionOffsetDays'
description: 'The offset (in days) for querying for consumption data'
value: 7
}
{
name: 'AzureOptimization_RecommendationsContainer'
description: 'The Storage Account container where recommendations are dumped to'
value: '"${recommendationsContainerName}"'
}
{
name: 'AzureOptimization_RemediationLogsContainer'
description: 'The Storage Account container where remediation logs are dumped to'
value: '"${remediationLogsContainerName}"'
}
{
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: 10000
}
{
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_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_RecommendPerfPeriodInDays'
description: 'The Period (in days) to look back for performance data from the Log Analytics workspaces'
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'
}
accessTier: 'Cool'
}
}
resource storageAccountName_default 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = {
name: '${storageAccountName}/default'
sku: {
name: 'Standard_LRS'
}
properties: {
cors: {
corsRules: []
}
deleteRetentionPolicy: {
enabled: false
}
}
dependsOn: [
storageAccountName_resource
]
}
resource storageAccountName_default_argDiskContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argDiskContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argVhdContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argVhdContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argVmContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argVmContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argAvailSetContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argAvailSetContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_advisorContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${advisorContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_consumptionContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${consumptionContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_aadObjectsContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${aadObjectsContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argLBsContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argLBsContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argAppGWsContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argAppGWsContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_argResContainersContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${argResContainersContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_rbacContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${rbacContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_recommendationsContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${recommendationsContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource storageAccountName_default_remediationLogsContainerName 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = {
name: '${storageAccountName}/default/${remediationLogsContainerName}'
properties: {
publicAccess: 'None'
}
dependsOn: [
storageAccountName_default
storageAccountName_resource
]
}
resource sqlServerName_resource 'Microsoft.Sql/servers@2019-06-01-preview' = {
name: sqlServerName
location: projectLocation
kind: 'v12.0'
properties: {
administratorLogin: sqlAdminLogin
administratorLoginPassword: sqlAdminPassword
version: '12.0'
publicNetworkAccess: 'Enabled'
}
}
resource sqlServerName_AllowAllWindowsAzureIps 'Microsoft.Sql/servers/firewallRules@2019-06-01-preview' = {
name: '${sqlServerName}/AllowAllWindowsAzureIps'
location: projectLocation
properties: {
endIpAddress: '0.0.0.0'
startIpAddress: '0.0.0.0'
}
dependsOn: [
sqlServerName_resource
]
}
resource sqlServerName_sqlDatabaseName 'Microsoft.Sql/servers/databases@2019-06-01-preview' = {
name: '${sqlServerName}/${sqlDatabaseName}'
location: projectLocation
sku: {
name: 'Basic'
tier: 'Basic'
capacity: 5
}
kind: 'v12.0,user'
properties: {
collation: 'SQL_Latin1_General_CP1_CI_AS'
maxSizeBytes: 2147483648
catalogCollation: 'SQL_Latin1_General_CP1_CI_AS'
zoneRedundant: false
readScale: 'Disabled'
readReplicaCount: 0
autoPauseDelay: 60
storageAccountType: 'GRS'
}
dependsOn: [
sqlServerName_resource
]
}
resource sqlServerName_sqlDatabaseName_default 'Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies@2019-06-01-preview' = {
name: '${sqlServerName}/${sqlDatabaseName}/default'
properties: {
retentionDays: sqlBackupRetentionDays
}
dependsOn: [
sqlServerName_sqlDatabaseName
sqlServerName_resource
]
}
resource automationAccountName_resource 'Microsoft.Automation/automationAccounts@2018-06-30' = {
name: automationAccountName
location: projectLocation
properties: {
sku: {
name: 'Basic'
}
}
}
resource automationAccountName_Az_Accounts_name 'Microsoft.Automation/automationAccounts/modules@2018-06-30' = {
name: '${automationAccountName}/${Az_Accounts.name}'
properties: {
contentLink: {
uri: Az_Accounts.url
}
}
dependsOn: [
automationAccountName_resource
]
}
resource automationAccountName_psModules_name 'Microsoft.Automation/automationAccounts/modules@2018-06-30' = [for item in psModules: {
name: '${automationAccountName}/${item.name}'
properties: {
contentLink: {
uri: item.url
}
}
dependsOn: [
automationAccountName_resource
automationAccountName_Az_Accounts_name
]