File: test-resources.bicep

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (244 lines) | stat: -rw-r--r-- 7,110 bytes parent folder | download
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
@description('The base resource name.')
param baseName string = resourceGroup().name

@description('Which Azure Region to deploy the resource to. Defaults to the resource group location.')
param location string = resourceGroup().location

@description('The tenant ID')
param tenantId string = ''

@description('The principal to assign the role to. This is application object id.')
param testApplicationOid string

@description('Specifies the name of the Data Collection Endpoint to create.')
param dataCollectionEndpointName string = 'az-dce'

@description('Specifies the name of the Data Collection Rule to create.')
param dataCollectionRuleName string = 'az-dcr'

// Currently variables can't be used as keys, so the stream name is also hardcoded in the 'streamDeclarations' of the
// 'dataCollectionRules' resource below.
var streamName = 'Custom-MyTableRawData'
var tableName = 'MyTable_CL'

resource id 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = {
  name: guid(resourceGroup().id)
  properties: {
    roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5ae67dd6-50cb-40e7-96ff-dc2bfa4b606b')
    principalId: testApplicationOid
  }
}

resource applicationInsightsComponent 'Microsoft.Insights/components@2020-02-02-preview' = {
  name: '${baseName}-appinsights-python'
  location: location
  kind: 'other'
  properties: {
    Application_Type: 'other'
    WorkspaceResourceId: primaryWorkspace.id
  }
}

resource dcrRoleAssignment 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = {
  name: guid(resourceGroup().id, dataCollectionRule.name, dataCollectionRule.id)
  properties: {
    roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '3913510d-42f4-4e42-8a64-420c390055eb')
    principalId: testApplicationOid
  }
}

resource dataCollectionEndpoint 'Microsoft.Insights/dataCollectionEndpoints@2021-04-01' = {
  name: dataCollectionEndpointName
  location: location
  properties: {
    networkAcls: {
      publicNetworkAccess: 'Enabled'
    }
  }
}

resource primaryWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
  name: '${baseName}-ws'
  location: location
  properties: {
    sku: {
      name: 'PerGB2018'
    }
    retentionInDays: 30
    features: {
      enableLogAccessUsingOnlyResourcePermissions: true
    }
    workspaceCapping: {
      dailyQuotaGb: -1
    }
    publicNetworkAccessForIngestion: 'Enabled'
    publicNetworkAccessForQuery: 'Enabled'
  }

  resource workspaceTable 'tables' = {
    name: tableName
    properties: {
      totalRetentionInDays: 30
      plan: 'Analytics'
      schema: {
        name: tableName
        columns: [
          {
            name: 'TimeGenerated'
            type: 'datetime'
            description: 'The time at which the data was generated'
          }
          {
            name: 'AdditionalContext'
            type: 'dynamic'
            description: 'Additional message properties'
          }
          {
            name: 'ExtendedColumn'
            type: 'string'
            description: 'An additional column extended at ingestion time'
          }
        ]
      }
      retentionInDays: 30
    }
  }
}

resource secondaryWorkspace 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
  name: '${baseName}-ws2'
  location: location
  properties: {
    sku: {
      name: 'PerGB2018'
    }
    retentionInDays: 30
    features: {
      enableLogAccessUsingOnlyResourcePermissions: true
    }
    workspaceCapping: {
      dailyQuotaGb: -1
    }
    publicNetworkAccessForIngestion: 'Enabled'
    publicNetworkAccessForQuery: 'Enabled'
  }

  resource workspaceTable 'tables' = {
    name: tableName
    properties: {
      totalRetentionInDays: 30
      plan: 'Analytics'
      schema: {
        name: tableName
        columns: [
          {
            name: 'TimeGenerated'
            type: 'datetime'
            description: 'The time at which the data was generated'
          }
          {
            name: 'AdditionalContext'
            type: 'dynamic'
            description: 'Additional message properties'
          }
          {
            name: 'ExtendedColumn'
            type: 'string'
            description: 'An additional column extended at ingestion time'
          }
        ]
      }
      retentionInDays: 30
    }
  }
}

resource dataCollectionRule 'Microsoft.Insights/dataCollectionRules@2021-09-01-preview' = {
  name: dataCollectionRuleName
  location: location
  properties: {
    dataCollectionEndpointId: dataCollectionEndpoint.id
    streamDeclarations: {
      'Custom-MyTableRawData': {
        columns: [
          {
            name: 'Time'
            type: 'datetime'
          }
          {
            name: 'Computer'
            type: 'string'
          }
          {
            name: 'AdditionalContext'
            type: 'string'
          }
        ]
      }
      'Custom-MyTableRawData2': {
        columns: [
          {
            name: 'Time'
            type: 'datetime'
          }
          {
            name: 'Computer'
            type: 'string'
          }
          {
            name: 'AdditionalContext'
            type: 'string'
          }
        ]
      }
    }
    destinations: {
      logAnalytics: [
        {
          workspaceResourceId: primaryWorkspace.id
          name: primaryWorkspace.name
        }
        {
          workspaceResourceId: secondaryWorkspace.id
          name: secondaryWorkspace.name
        }
      ]
    }
    dataFlows: [
      {
        streams: [
          streamName
        ]
        destinations: [
          primaryWorkspace.name
        ]
        transformKql: 'source | extend jsonContext = parse_json(AdditionalContext) | project TimeGenerated = Time, Computer, AdditionalContext = jsonContext, ExtendedColumn=tostring(jsonContext.CounterName)'
        outputStream: 'Custom-${tableName}'
      }
      {
        streams: [
          '${streamName}2'
        ]
        destinations: [
          secondaryWorkspace.name
        ]
        transformKql: 'source | extend jsonContext = parse_json(AdditionalContext) | project TimeGenerated = Time, Computer, AdditionalContext = jsonContext, ExtendedColumn=tostring(jsonContext.CounterName)'
        outputStream: 'Custom-${tableName}'
      }
    ]
  }
  dependsOn: [
    primaryWorkspace::workspaceTable
    secondaryWorkspace::workspaceTable
  ]
}

output APPLICATIONINSIGHTS_CONNECTION_STRING string = applicationInsightsComponent.properties.ConnectionString
output METRICS_RESOURCE_ID string = applicationInsightsComponent.id
output AZURE_MONITOR_WORKSPACE_ID string = primaryWorkspace.properties.customerId
output AZURE_MONITOR_SECONDARY_WORKSPACE_ID string = secondaryWorkspace.properties.customerId
output AZURE_MONITOR_DCE string = dataCollectionEndpoint.properties.logsIngestion.endpoint
output AZURE_MONITOR_DCR_ID string = dataCollectionRule.properties.immutableId
output AZURE_MONITOR_STREAM_NAME string = streamName
output AZURE_MONITOR_TABLE_NAME string = tableName
output AZURE_MONITOR_TENANT_ID string = tenantId