-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.bicep
133 lines (113 loc) · 4.06 KB
/
main.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
@description('Location of the automation account')
param location string = resourceGroup().location
@description('Automation account name')
param name string
@description('Automation account sku')
@allowed([
'Free'
'Basic'
])
param sku string = 'Basic'
@description('Modules to import into automation account')
@metadata({
name: 'Module name'
version: 'Module version or specify latest to get the latest version'
uri: 'Module package uri, e.g. https://www.powershellgallery.com/api/v2/package'
})
param modules array = []
@description('Runbooks to import into automation account')
@metadata({
runbookName: 'Runbook name'
runbookUri: 'Runbook URI'
runbookType: 'Runbook type: Graph, Graph PowerShell, Graph PowerShellWorkflow, PowerShell, PowerShell Workflow, Script'
logProgress: 'Enable progress logs'
logVerbose: 'Enable verbose logs'
})
param runbooks array = []
@description('Enable delete lock')
param enableDeleteLock bool = false
@description('Enable diagnostic logs')
param enableDiagnostics bool = false
@description('Storage account name. Only required if enableDiagnostics is set to true.')
param diagnosticStorageAccountName string = ''
@description('Storage account resource group. Only required if enableDiagnostics is set to true.')
param diagnosticStorageAccountResourceGroup string = ''
@description('Log analytics workspace name. Only required if enableDiagnostics is set to true.')
param logAnalyticsWorkspaceName string = ''
@description('Log analytics workspace resource group. Only required if enableDiagnostics is set to true.')
param logAnalyticsResourceGroup string = ''
@description('Log analytics workspace subscription id (if differs from current subscription). Only required if enableDiagnostics is set to true.')
param logAnalyticsSubscriptionId string = subscription().subscriptionId
var lockName = '${automationAccount.name}-lck'
var diagnosticsName = '${automationAccount.name}-dgs'
resource automationAccount 'Microsoft.Automation/automationAccounts@2020-01-13-preview' = {
name: name
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
sku: {
name: sku
}
}
}
resource automationAccountModules 'Microsoft.Automation/automationAccounts/modules@2020-01-13-preview' = [for module in modules: {
parent: automationAccount
name: module.name
properties: {
contentLink: {
uri: module.version == 'latest' ? '${module.uri}/${module.name}' : '${module.uri}/${module.name}/${module.version}'
version: module.version == 'latest' ? null : module.version
}
}
}]
resource runbook 'Microsoft.Automation/automationAccounts/runbooks@2019-06-01' = [for runbook in runbooks: {
parent: automationAccount
name: runbook.runbookName
location: location
properties: {
runbookType: runbook.runbookType
logProgress: runbook.logProgress
logVerbose: runbook.logVerbose
publishContentLink: {
uri: runbook.runbookUri
}
}
}]
resource lock 'Microsoft.Authorization/locks@2016-09-01' = if (enableDeleteLock) {
scope: automationAccount
name: lockName
properties: {
level: 'CanNotDelete'
}
}
resource diagnostics 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = if (enableDiagnostics) {
scope: automationAccount
name: diagnosticsName
properties: {
workspaceId: resourceId(logAnalyticsSubscriptionId, logAnalyticsResourceGroup, 'Microsoft.OperationalInsights/workspaces', logAnalyticsWorkspaceName)
storageAccountId: resourceId(diagnosticStorageAccountResourceGroup, 'Microsoft.Storage/storageAccounts', diagnosticStorageAccountName)
logs: [
{
category: 'JobLogs'
enabled: true
}
{
category: 'JobStreams'
enabled: true
}
{
category: 'DscNodeStatus'
enabled: true
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
}
]
}
}
output systemIdentityPrincipalId string = automationAccount.identity.principalId