-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.bicep
295 lines (280 loc) · 9.04 KB
/
template.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
param connections_twitter_name string = 'twitter'
param connections_keyvault_name string = 'keyvault'
param connections_linkedinv2_name string = 'linkedinv2'
param key_vault_name string = 'scxpstkv${uniqueString(resourceGroup().name)}'
param managed_identity_name string = 'scposter${uniqueString(resourceGroup().name)}'
param workflows_socialxposter_name string = 'socialxposterv2'
param resource_group_location string = resourceGroup().location
@secure()
param mastodon_key_value string
param mastodon_host string = 'mastodon.online'
// Key Vault and Secret
resource key_vault_resource 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: key_vault_name
location: resource_group_location
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
accessPolicies: [
{
tenantId: subscription().tenantId
objectId: managed_service_identity_kv_resource.properties.principalId
permissions: {
certificates: []
keys: []
secrets: [
'get'
]
}
}
]
enabledForDeployment: false
enabledForDiskEncryption: false
enabledForTemplateDeployment: false
enableSoftDelete: true
softDeleteRetentionInDays: 7
enableRbacAuthorization: false
publicNetworkAccess: 'Enabled'
}
}
resource vaults_socialxpostkv_name_MastodonKey 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
parent: key_vault_resource
name: 'MastodonKey'
properties: {
value: mastodon_key_value
attributes: {
enabled: true
}
}
}
// End Key Vault and secret
// Managed Service Identity
resource managed_service_identity_kv_resource 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: managed_identity_name
location: resource_group_location
}
// End of Managed Service Identity
// Logic Apps Connection Definitions
resource connections_keyvault_resource 'Microsoft.Web/connections@2016-06-01' = {
name: connections_keyvault_name
location: resource_group_location
properties: {
displayName: 'KeyVaultMIAccess'
parameterValueType: 'Alternative'
alternativeParameterValues: {
vaultName: key_vault_name
}
customParameterValues: {}
api: {
name: 'keyvault'
displayName: 'Azure Key Vault'
description: 'Azure Key Vault is a service to securely store and access secrets.'
iconUri: 'https://connectoricons-prod.azureedge.net/releases/v1.0.1597/1.0.1597.3005/keyvault/icon.png'
brandColor: '#0079d6'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'keyvault')
type: 'Microsoft.Web/locations/managedApis'
}
}
}
resource connections_linkedinv2_resource 'Microsoft.Web/connections@2016-06-01' = {
name: connections_linkedinv2_name
location: resource_group_location
properties: {
displayName: 'LinkedIn V2'
api: {
name: connections_linkedinv2_name
displayName: 'LinkedIn V2'
description: 'Amplify your content\'s reach by easily sharing on LinkedIn. The connector targets LinkedIn API version 2.'
iconUri: 'https://connectoricons-prod.azureedge.net/releases/v1.0.1604/1.0.1604.3062/linkedinv2/icon.png'
brandColor: '#007AB9'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'linkedinv2')
type: 'Microsoft.Web/locations/managedApis'
}
}
}
resource connections_twitter_name_resource 'Microsoft.Web/connections@2016-06-01' = {
name: connections_twitter_name
location: resource_group_location
properties: {
displayName: 'TwitterConnection'
api: {
name: connections_twitter_name
displayName: 'Twitter'
description: 'Twitter is an online social networking service that enables users to send and receive short messages called \'tweets\'. Connect to Twitter to manage your tweets. You can perform various actions such as send tweet, search, view followers, etc.'
iconUri: 'https://connectoricons-prod.azureedge.net/releases/v1.0.1607/1.0.1607.3068/twitter/icon.png'
brandColor: '#5fa9dd'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'twitter')
type: 'Microsoft.Web/locations/managedApis'
}
}
}
// End Logic Apps Connection Definitions
// Azure Logic App
resource workflows_socialxposter_resource 'Microsoft.Logic/workflows@2019-05-01' = {
name: workflows_socialxposter_name
location: resource_group_location
dependsOn: [
managed_service_identity_kv_resource
]
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${managed_service_identity_kv_resource.name}' : {}
}
}
properties: {
state: 'Enabled'
definition: {
'$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
contentVersion: '1.0.0.0'
parameters: {
'$connections': {
defaultValue: {
}
type: 'Object'
}
MastodonHost: {
defaultValue: mastodon_host
type: 'String'
}
}
triggers: {
manual: {
type: 'Request'
kind: 'Http'
inputs: {
method: 'POST'
schema: {
properties: {
ImageRef: {
type: 'string'
}
Link: {
type: 'string'
}
Summary: {
type: 'string'
}
Title: {
type: 'string'
}
}
type: 'object'
}
}
}
}
actions: {
Get_secret: {
runAfter: {
}
type: 'ApiConnection'
inputs: {
host: {
connection: {
name: '@parameters(\'$connections\')[\'keyvault\'][\'connectionId\']'
}
}
method: 'get'
path: '/secrets/@{encodeURIComponent(\'MastodonKey\')}/value'
}
}
HTTP: {
runAfter: {
Get_secret: [
'Succeeded'
]
}
type: 'Http'
inputs: {
body: 'status="@{triggerBody()?[\'Title\']}\n@{triggerBody()?[\'Summary\']}\n@{triggerBody()?[\'Link\']}"'
headers: {
Authorization: 'Bearer @{body(\'Get_secret\')?[\'value\']}'
'Content-Type': 'application/x-www-form-urlencoded'
}
method: 'POST'
uri: 'https://@{parameters(\'MastodonHost\')}/api/v1/statuses'
}
}
Post_a_tweet: {
runAfter: {
}
type: 'ApiConnection'
inputs: {
host: {
connection: {
name: '@parameters(\'$connections\')[\'twitter\'][\'connectionId\']'
}
}
method: 'post'
path: '/posttweet'
queries: {
tweetText: '@{triggerBody()?[\'Summary\']}\n@{triggerBody()?[\'Link\']}'
}
}
}
Share_an_article_V2: {
runAfter: {
}
type: 'ApiConnection'
inputs: {
body: {
content: {
'content-image-url': '@triggerBody()?[\'ImageRef\']'
'content-url': '@triggerBody()?[\'Link\']'
title: '@triggerBody()?[\'Title\']'
}
distribution: {
linkedInDistributionTarget: {
visibleToGuest: true
}
}
text: {
text: '@triggerBody()?[\'Summary\']'
}
}
host: {
connection: {
name: '@parameters(\'$connections\')[\'linkedinv2\'][\'connectionId\']'
}
}
method: 'post'
path: '/v2/people/shares'
}
}
}
outputs: {
}
}
parameters: {
'$connections': {
value: {
keyvault: {
connectionId: connections_keyvault_resource.id
connectionName: 'keyvault'
connectionProperties: {
authentication: {
type: 'ManagedServiceIdentity'
}
}
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'keyvault')
}
linkedinv2: {
connectionId: connections_linkedinv2_resource.id
connectionName: 'linkedinv2'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'linkedinv2')
}
twitter: {
connectionId: connections_twitter_name_resource.id
connectionName: 'twitter'
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', resource_group_location, 'twitter')
}
}
}
}
}
}
// End of Azure Logic App