-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLogicApp.yaml
More file actions
279 lines (279 loc) · 11.3 KB
/
Copy pathLogicApp.yaml
File metadata and controls
279 lines (279 loc) · 11.3 KB
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
$schema: https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
contentVersion: 1.0.0.0
parameters:
location:
type: string
metadata:
description: The region where resources are deployed
defaultValue: '[resourceGroup().location]'
logicAppName:
type: string
metadata:
description: Name of Logic App
storageAccountName:
type: string
metadata:
description: Name of Storage Account
tableStorageTableName:
type: string
metadata:
description: Name of table in Table Storage
defaultValue: DeploymentHistory
armConnectorName:
type: string
metadata:
description: Name of ARM connector
tableStorageConnectorName:
type: string
metadata:
description: Name of Storage connector
variables:
logicApp:
name: "[parameters('logicAppName')]"
apiVersion: "[providers('Microsoft.Logic', 'workflows').apiVersions[0]]"
location: "[parameters('location')]"
storageAccount:
name: "[parameters('storageAccountName')]"
tableStorageTableName: "[parameters('tableStorageTableName')]"
connectors:
apiVersion: "[providers('Microsoft.Web', 'connections').apiVersions[0]]"
location: "[parameters('location')]"
subscriptionId: '[subscription().subscriptionId]'
arm:
id: "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/arm')]"
name: "[parameters('armConnectorName')]"
connectionId: "[concat(resourceGroup().id, '/providers/Microsoft.Web/connections/', parameters('armConnectorName'))]"
resourceGroup: '[resourceGroup().name]'
apiVersion: 2016-06-01
azuretables:
id: "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/azuretables')]"
name: "[parameters('tableStorageConnectorName')]"
connectionId: "[concat(resourceGroup().id, '/providers/Microsoft.Web/connections/', parameters('tableStorageConnectorName'))]"
tableName: "[variables('storageAccount').tableStorageTableName]"
tags:
author: Justin Yoo
profile: https://twitter.com/justinchronicle
projectUrl: https://github.com/aliencube/ARM-Deployment-History-Cleaner
repositoryUrl: https://github.com/aliencube/ARM-Deployment-History-Cleaner
license: https://raw.githubusercontent.com/aliencube/ARM-Deployment-History-Cleaner/master/LICENSE
resources:
- comments: '### RESOURCE - LOGIC APP ###'
apiVersion: "[variables('logicApp').apiVersion]"
type: Microsoft.Logic/workflows
name: "[variables('logicApp').name]"
location: "[variables('logicApp').location]"
tags: "[variables('tags')]"
properties:
state: Enabled
parameters:
$connections:
value:
arm:
connectionId: "[variables('connectors').arm.connectionId]"
connectionName: "[variables('connectors').arm.name]"
id: "[variables('connectors').arm.id]"
azuretables:
connectionId: "[variables('connectors').azuretables.connectionId]"
connectionName: "[variables('connectors').azuretables.name]"
id: "[variables('connectors').azuretables.id]"
arm:
value:
subscriptionId: "[variables('connectors').subscriptionId]"
resourceGroup: "[variables('connectors').arm.resourceGroup]"
apiVersion: "[variables('connectors').arm.apiVersion]"
azuretables:
value:
tableName: "[variables('connectors').azuretables.tableName]"
definition:
$schema: https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#
contentVersion: 1.0.0.0
parameters:
$connections:
type: object
defaultValue: {}
arm:
type: object
defaultValue: {}
azuretables:
type: object
defaultValue: {}
triggers:
manual:
type: Request
kind: Http
inputs:
schema:
type: object
properties:
resourceGroup:
type: string
actions:
InitialiseUntilLoopIndicator:
type: InitializeVariable
runAfter: {}
description: Initialises indicator for the until-loop.
inputs:
variables:
- type: Boolean
name: HasMoreDeploymentHistories
value: true
InitialiseResourceGroup:
type: InitializeVariable
runAfter: {}
description: Initialises resource group.
inputs:
variables:
- type: String
name: ResourceGroup
value: "@{if(empty(coalesce(triggerBody()?['resourceGroup'], '')), parameters('arm')['resourceGroup'], triggerBody()?['resourceGroup'])}"
GetTables:
type: ApiConnection
runAfter: {}
description: Gets the list of tables from the table storage.
inputs:
host:
connection:
name: "@parameters('$connections')['azuretables']['connectionId']"
method: get
path: /Tables
GetTable:
type: Query
runAfter:
GetTables:
- Succeeded
description: Filters the list of tables.
inputs:
from: "@body('GetTables')?['value']"
where: "@equals(item()?['TableName'], parameters('azuretables')['tableName'])"
IfTableNotExist:
type: If
runAfter:
GetTable:
- Succeeded
description: Checks whether the table exists or not.
expression:
and:
- equals:
- "@length(body('GetTable'))"
- 0
actions:
CreateTable:
type: ApiConnection
runAfter: {}
description: Creates a new table.
inputs:
host:
connection:
name: "@parameters('$connections')['azuretables']['connectionId']"
method: post
path: /Tables
body: "@{parameters('azuretables')['tableName']}"
LoopWhileDeploymentHistoriesExist:
type: Until
runAfter:
InitialiseUntilLoopIndicator:
- Succeeded
InitialiseResourceGroup:
- Succeeded
IfTableNotExist:
- Succeeded
description: Loops until no deployment histories exist.
expression: "@equals(variables('HasMoreDeploymentHistories'), false)"
limit:
count: 20
timeout: PT1H
actions:
FetchDeploymentHistories:
type: ApiConnection
runAfter: {}
description: Fetches the list of deployment histories.
inputs:
host:
connection:
name: "@parameters('$connections')['arm']['connectionId']"
method: get
path: /subscriptions/@{encodeURIComponent(parameters('arm')['subscriptionId'])}/resourcegroups/@{encodeURIComponent(variables('ResourceGroup'))}/providers/Microsoft.Resources/deployments
queries:
x-ms-api-version: "@{parameters('arm')['apiVersion']}"
CheckWhetherMoreDeploymentHistoriesExist:
type: If
runAfter:
FetchDeploymentHistories:
- Succeeded
description: Checks whether more deployment histories exist or not.
expression:
and:
- greater:
- "@length(body('FetchDeploymentHistories')?['value'])"
- 0
actions:
LoopDeploymentHistories:
type: Foreach
runAfter: {}
description: Loop deployment histories.
foreach: "@body('FetchDeploymentHistories')?['value']"
runtimeConfiguration:
concurrency:
repetitions: 50
actions:
ComposeDataSet:
type: Compose
runAfter: {}
inputs:
partitionKey: "@variables('ResourceGroup')"
rowKey: "@items('LoopDeploymentHistories')?['name']"
entity:
dateRun: "@items('LoopDeploymentHistories')?['properties']?['timestamp']"
details: "@{string(items('LoopDeploymentHistories'))}"
StoreDeploymentHistory:
type: ApiConnection
runAfter:
ComposeDataSet:
- Succeeded
description: Stores the deployment history to table storage.
inputs:
host:
connection:
name: "@parameters('$connections')['azuretables']['connectionId']"
method: put
path: /Tables/@{encodeURIComponent(parameters('azuretables')['tableName'])}/entities(PartitionKey='@{encodeURIComponent(outputs('ComposeDataSet')?['partitionKey'])}',RowKey='@{encodeURIComponent(outputs('ComposeDataSet')?['rowKey'])}')
body: "@outputs('ComposeDataSet')?['entity']"
DeleteDeploymentHistory:
type: ApiConnection
runAfter:
StoreDeploymentHistory:
- Succeeded
description: Delete deployment history.
inputs:
host:
connection:
name: "@parameters('$connections')['arm']['connectionId']"
method: delete
path: /subscriptions/@{encodeURIComponent(parameters('arm')['subscriptionId'])}/resourcegroups/@{encodeURIComponent(variables('ResourceGroup'))}/providers/Microsoft.Resources/deployments/@{encodeURIComponent(items('LoopDeploymentHistories')?['name'])}
queries:
x-ms-api-version: "@{parameters('arm')['apiVersion']}"
else:
actions:
SetVariableForDeploymentHistories:
type: SetVariable
runAfter: {}
description: Sets the variable value to 'false' to exit the loop.
inputs:
name: HasMoreDeploymentHistories
value: false
ChecksDeployments:
type: ApiConnection
runAfter:
LoopWhileDeploymentHistoriesExist:
- Succeeded
description: Checks whether more deployment histories exist or not. This should return an empty array.
inputs:
host:
connection:
name: "@parameters('$connections')['arm']['connectionId']"
method: get
path: /subscriptions/@{encodeURIComponent(parameters('arm')['subscriptionId'])}/resourcegroups/@{encodeURIComponent(variables('ResourceGroup'))}/providers/Microsoft.Resources/deployments
queries:
x-ms-api-version: "@{parameters('arm')['apiVersion']}"
outputs: {}
outputs: {}