|
| 1 | +@description('Base name of the resource to be created.') |
| 2 | +@minLength(16) |
| 3 | +param baseName string = resourceGroup().name |
| 4 | + |
| 5 | +@description('The location where the resources will be created.') |
| 6 | +param location string = resourceGroup().location |
| 7 | + |
| 8 | +@description('The suffix for the storage endpoint, typically based on the Azure environment.') |
| 9 | +param storageEndpointSuffix string = environment().suffixes.storage |
| 10 | + |
| 11 | +@description('Indicates if the tenant is a TME tenant. If true, local (SAS) authentication is enabled.') |
| 12 | +param tenantIsTME bool = false |
| 13 | + |
| 14 | +@description('The client OID to grant access to test resources.') |
| 15 | +param testApplicationOid string |
| 16 | + |
| 17 | +var eventhubNamespaceName = 'eh-${baseName}' |
| 18 | +var storageAccountName = 'blb${baseName}' |
| 19 | +var eventHubName = 'testeventhub' |
| 20 | + |
| 21 | +var eventHubsDataOwnerRoleId = 'f526a384-b230-433a-b45c-95f59c4a2dec' |
| 22 | +var blobDataOwnerRoleId = 'b7e6dc6d-f1e8-4753-8033-0f276bb0955b' |
| 23 | +var azureContributorRoleId = 'b24988ac-6180-42a0-ab88-20f7382dd24c' |
| 24 | + |
| 25 | +resource eventhubNamespace 'Microsoft.EventHub/namespaces@2024-05-01-preview' = { |
| 26 | + name: eventhubNamespaceName |
| 27 | + location: location |
| 28 | + sku: { |
| 29 | + name: 'Standard' |
| 30 | + tier: 'Standard' |
| 31 | + capacity: 5 |
| 32 | + } |
| 33 | + properties: { |
| 34 | + geoDataReplication: { |
| 35 | + maxReplicationLagDurationInSeconds: 0 |
| 36 | + locations: [ |
| 37 | + { |
| 38 | + locationName: location |
| 39 | + roleType: 'Primary' |
| 40 | + } |
| 41 | + ] |
| 42 | + } |
| 43 | + minimumTlsVersion: '1.2' |
| 44 | + publicNetworkAccess: 'Enabled' |
| 45 | + disableLocalAuth: !tenantIsTME // Disable local auth for TME tenants |
| 46 | + zoneRedundant: false |
| 47 | + isAutoInflateEnabled: false |
| 48 | + maximumThroughputUnits: 0 |
| 49 | + kafkaEnabled: true |
| 50 | + } |
| 51 | + resource authorization 'authorizationrules@2024-05-01-preview' = { |
| 52 | + name: 'RootManageSharedAccessKey' |
| 53 | + properties: { |
| 54 | + rights: [ |
| 55 | + 'Listen' |
| 56 | + 'Manage' |
| 57 | + 'Send' |
| 58 | + ] |
| 59 | + } |
| 60 | + } |
| 61 | + resource authorizedListenOnly 'AuthorizationRules@2017-04-01' = { |
| 62 | + name: 'ListenOnly' |
| 63 | + properties: { |
| 64 | + rights: [ |
| 65 | + 'Listen' |
| 66 | + ] |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + resource authorizedSendOnly 'AuthorizationRules@2017-04-01' = { |
| 71 | + name: 'SendOnly' |
| 72 | + properties: { |
| 73 | + rights: [ |
| 74 | + 'Send' |
| 75 | + ] |
| 76 | + } |
| 77 | + } |
| 78 | + resource eventHub 'eventhubs@2024-05-01-preview' = { |
| 79 | + name: eventHubName |
| 80 | + properties: { |
| 81 | + messageTimestampDescription: { |
| 82 | + timestampType: 'LogAppend' |
| 83 | + } |
| 84 | + retentionDescription: { |
| 85 | + cleanupPolicy: 'Delete' |
| 86 | + retentionTimeInHours: 24 |
| 87 | + } |
| 88 | + messageRetentionInDays: 1 |
| 89 | + partitionCount: 4 |
| 90 | + status: 'Active' |
| 91 | + } |
| 92 | + resource consumerGroup 'consumergroups@2024-05-01-preview' = { |
| 93 | + name: '$Default' |
| 94 | + properties: {} |
| 95 | + } |
| 96 | + |
| 97 | + resource defaultGroup 'consumergroups@2024-05-01-preview' = { |
| 98 | + name: 'defaultGroup' |
| 99 | + properties: {} |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + resource eventhubNamespace_networkruleset_default 'networkrulesets@2024-05-01-preview' = { |
| 104 | + name: 'default' |
| 105 | + properties: { |
| 106 | + publicNetworkAccess: 'Enabled' |
| 107 | + defaultAction: 'Allow' |
| 108 | + virtualNetworkRules: [] |
| 109 | + ipRules: [] |
| 110 | + trustedServiceAccessEnabled: false |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +resource roleAssignments_ehDataOwner 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 116 | + name: guid(eventhubNamespace.id, 'Azure Event Hubs Data Owner') |
| 117 | + |
| 118 | + properties: { |
| 119 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', eventHubsDataOwnerRoleId) // Azure Event Hubs Data Owner |
| 120 | + principalId: testApplicationOid |
| 121 | + } |
| 122 | + dependsOn: [ |
| 123 | + eventhubNamespace::eventHub |
| 124 | + storageAccount |
| 125 | + ] |
| 126 | +} |
| 127 | + |
| 128 | +resource roleAssignments_contributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 129 | + name: guid(eventhubNamespace.id, 'Azure Contributor') |
| 130 | + |
| 131 | + properties: { |
| 132 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', azureContributorRoleId) // Azure Contributor |
| 133 | + principalId: testApplicationOid |
| 134 | + } |
| 135 | + dependsOn: [ |
| 136 | + eventhubNamespace::eventHub |
| 137 | + storageAccount |
| 138 | + ] |
| 139 | +} |
| 140 | + |
| 141 | +resource roleAssignments_storageDataOwner 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 142 | + name: guid(eventhubNamespace.id, 'Storage Blob Data Owner') |
| 143 | + |
| 144 | + properties: { |
| 145 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', blobDataOwnerRoleId) // Storage Blob Data Owner |
| 146 | + principalId: testApplicationOid |
| 147 | + } |
| 148 | + dependsOn: [ |
| 149 | + eventhubNamespace::eventHub |
| 150 | + storageAccount |
| 151 | + ] |
| 152 | +} |
| 153 | + |
| 154 | +resource storageAccount 'Microsoft.Storage/storageAccounts@2024-01-01' = { |
| 155 | + name: storageAccountName |
| 156 | + location: location |
| 157 | + sku: { |
| 158 | + name: 'Standard_LRS' |
| 159 | + } |
| 160 | + kind: 'BlobStorage' |
| 161 | + properties: { |
| 162 | + allowCrossTenantReplication: false |
| 163 | + minimumTlsVersion: 'TLS1_2' |
| 164 | + allowBlobPublicAccess: false |
| 165 | + allowSharedKeyAccess: false |
| 166 | + networkAcls: { |
| 167 | + bypass: 'AzureServices' |
| 168 | + virtualNetworkRules: [] |
| 169 | + ipRules: [] |
| 170 | + defaultAction: 'Allow' |
| 171 | + } |
| 172 | + supportsHttpsTrafficOnly: true |
| 173 | + encryption: { |
| 174 | + services: { |
| 175 | + file: { |
| 176 | + keyType: 'Account' |
| 177 | + enabled: true |
| 178 | + } |
| 179 | + blob: { |
| 180 | + keyType: 'Account' |
| 181 | + enabled: true |
| 182 | + } |
| 183 | + } |
| 184 | + keySource: 'Microsoft.Storage' |
| 185 | + } |
| 186 | + accessTier: 'Hot' |
| 187 | + } |
| 188 | + resource storageAccount_default 'blobServices@2024-01-01' = { |
| 189 | + name: 'default' |
| 190 | + properties: { |
| 191 | + cors: { |
| 192 | + corsRules: [] |
| 193 | + } |
| 194 | + deleteRetentionPolicy: { |
| 195 | + allowPermanentDelete: false |
| 196 | + enabled: false |
| 197 | + } |
| 198 | + } |
| 199 | + resource storageAccount_blobContainer 'containers@2019-04-01' = { |
| 200 | + name: 'container' |
| 201 | + properties: {} |
| 202 | + } |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | +// Outputs |
| 207 | +output EVENTHUB_NAME string = eventhubNamespace::eventHub.name |
| 208 | +output EVENTHUBS_NAMESPACE string = eventhubNamespace.name |
| 209 | + |
| 210 | +output EVENTHUBS_HOST string = replace( |
| 211 | + replace(eventhubNamespace.properties.serviceBusEndpoint, ':443/', ''), |
| 212 | + 'https://', |
| 213 | + '' |
| 214 | +) |
| 215 | +//output EVENTHUBS_CONNECTION_STRING string = listKeys(eventHubAuthRule.id, eventHubAuthRule.apiVersion).primaryConnectionString |
| 216 | +output AZURE_STORAGE_ACCOUNT_NAME string = storageAccount.name |
| 217 | +//output AZURE_STORAGE_ACCOUNT_KEY string = listKeys(storage.id, storage.apiVersion).keys[0].value |
| 218 | +output STORAGE_ENDPOINT_SUFFIX string = storageEndpointSuffix |
| 219 | +output AZURE_STORAGE_BLOB_ENDPOINT string = storageAccount.properties.primaryEndpoints.blob |
| 220 | +output RESOURCE_GROUP string = resourceGroup().name |
0 commit comments