-
Notifications
You must be signed in to change notification settings - Fork 0
/
automation.bicep
126 lines (115 loc) · 3.73 KB
/
automation.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
param automationAccountName string
param location string = resourceGroup().location
param today string = utcNow('yyyyMMddTHHmmssZ')
@description('The timezone to align schedules to. (Eg. "Europe/London" or "America/Los_Angeles")')
param timezone string = 'Etc/UTC'
var tomorrow = dateTimeAdd(today, 'P1D','yyyy-MM-dd')
var automationStartTimeMidnight = '${take(tomorrow,10)}T00:01:00+00:00'
var automationStartTime9am = '${take(tomorrow,10)}T09:00:00+00:00'
resource automationAccount 'Microsoft.Automation/automationAccounts@2022-08-08' = {
name: automationAccountName
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
sku: {
name: 'Free'
}
}
}
resource runbookCleanRG 'Microsoft.Automation/automationAccounts/runbooks@2022-08-08' = {
parent: automationAccount
name: 'CleanRgResources'
location: location
properties: {
logVerbose: true
logProgress: true
runbookType: 'Script'
publishContentLink: {
uri: 'https://raw.githubusercontent.com/Gordonby/Snippets/master/AzureSubscriptionBootstrap/cleanRgResources.ps1'
version: '1.0.0.0'
}
description: 'Deletes the resources in tagged resource groups'
}
}
resource runbookUntaggedRGs 'Microsoft.Automation/automationAccounts/runbooks@2022-08-08' = {
parent: automationAccount
name: 'TagResourceGroupsForDeletion'
location: location
properties: {
logVerbose: true
logProgress: true
runbookType: 'Script'
publishContentLink: {
uri: 'https://raw.githubusercontent.com/Gordonby/Snippets/master/AzureSubscriptionBootstrap/tagResourceGroups.ps1'
version: '1.0.0.0'
}
description: 'Deletes the resources in tagged resource groups'
}
}
resource runbookDeleteRGs 'Microsoft.Automation/automationAccounts/runbooks@2022-08-08' = {
parent: automationAccount
name: 'DeleteResourceGroups'
location: location
properties: {
logVerbose: true
logProgress: true
runbookType: 'Script'
publishContentLink: {
uri: 'https://raw.githubusercontent.com/Gordonby/Snippets/master/AzureSubscriptionBootstrap/deleteResourceGroups.ps1'
version: '1.0.0.0'
}
description: 'Deletes resource groups'
}
}
resource automationScheduleNight 'Microsoft.Automation/automationAccounts/schedules@2022-08-08' = {
parent: automationAccount
name: 'Midnight'
properties: {
startTime: automationStartTimeMidnight
expiryTime: '9999-12-31T23:59:00+00:00'
interval: 1
frequency: 'Day'
timeZone: timezone
description: 'Daily out of hours schedule'
}
}
resource automationScheduleMorn 'Microsoft.Automation/automationAccounts/schedules@2022-08-08' = {
parent: automationAccount
name: '9am'
properties: {
startTime: automationStartTime9am
expiryTime: '9999-12-31T23:59:00+00:00'
interval: 1
frequency: 'Day'
timeZone: timezone
description: 'Daily out of hours schedule'
}
}
var runbookNames = [runbookCleanRG.name, runbookDeleteRGs.name]
resource automationJobNightSchedules 'Microsoft.Automation/automationAccounts/jobSchedules@2022-08-08' = [for runbookName in runbookNames : {
parent: automationAccount
name: guid(automationAccount.id, runbookName, automationScheduleNight.name)
properties: {
schedule: {
name: automationScheduleNight.name
}
runbook: {
name: runbookName
}
}
}]
resource automationJobMornSchedule 'Microsoft.Automation/automationAccounts/jobSchedules@2022-08-08' = {
parent: automationAccount
name: guid(automationAccount.id, runbookUntaggedRGs.name, automationScheduleNight.name)
properties: {
schedule: {
name: automationScheduleMorn.name
}
runbook: {
name: runbookUntaggedRGs.name
}
}
}
output automationAccountPrincipalId string = automationAccount.identity.principalId