Skip to content

Commit b5d6dee

Browse files
committed
Support detect Azure Event Hubs: produce message only. Try to connect by connection string, but failed: Cant not get connection string. Issue created: Azure/bicep-registry-modules#3638
1 parent 41cc716 commit b5d6dee

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

cli/azd/resources/scaffold/templates/main.bicept

+3
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ output AZURE_CACHE_REDIS_ID string = resources.outputs.AZURE_CACHE_REDIS_ID
5959
{{- if .DbPostgres}}
6060
output AZURE_POSTGRES_FLEXIBLE_SERVER_ID string = resources.outputs.AZURE_POSTGRES_FLEXIBLE_SERVER_ID
6161
{{- end}}
62+
{{- if .AzureEventHubs }}
63+
output AZURE_EVENT_HUBS_ID string = resources.outputs.AZURE_EVENT_HUBS_ID
64+
{{- end}}
6265
{{ end}}

cli/azd/resources/scaffold/templates/resources.bicept

+28-7
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,23 @@ module postgreServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:0.1.4
126126
}
127127
}
128128
{{- end}}
129-
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
129+
{{- if .AzureEventHubs }}
130130

131-
module eventHubs 'br/public:avm/res/event-hub/namespace:0.7.1' = {
132-
name: 'eventHubs'
131+
module eventHubNamespace 'br/public:avm/res/event-hub/namespace:0.7.1' = {
132+
name: 'eventHubNamespace'
133133
params: {
134134
name: '${abbrs.eventHubNamespaces}${resourceToken}'
135135
location: location
136136
roleAssignments: [
137+
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
137138
{{- range .Services}}
138139
{
139140
principalId: {{bicepName .Name}}Identity.outputs.principalId
140141
principalType: 'ServicePrincipal'
141142
roleDefinitionIdOrName: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'f526a384-b230-433a-b45c-95f59c4a2dec')
142143
}
143144
{{- end}}
145+
{{- end}}
144146
]
145147
eventhubs: [
146148
{{- range $eventHubName := .AzureEventHubs.EventHubNames}}
@@ -307,15 +309,17 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
307309
secretRef: 'redis-pass'
308310
}
309311
{{- end}}
312+
{{- if .AzureEventHubs }}
313+
{
314+
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_NAMESPACE'
315+
value: eventHubNamespace.outputs.name
316+
}
317+
{{- end}}
310318
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
311319
{
312320
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
313321
value: ''
314322
}
315-
{
316-
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_NAMESPACE'
317-
value: eventHubs.outputs.name
318-
}
319323
{
320324
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_MANAGEDIDENTITYENABLED'
321325
value: 'true'
@@ -325,6 +329,20 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
325329
value: {{bicepName .Name}}Identity.outputs.clientId
326330
}
327331
{{- end}}
332+
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingConnectionString) }}
333+
{
334+
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
335+
value: listKeys('${eventHubNamespace.outputs.resourceId}/AuthorizationRules/RootManageSharedAccessKey', '2024-01-01').primaryConnectionString # Issue: https://github.com/Azure/bicep-registry-modules/issues/3638
336+
}
337+
{
338+
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_MANAGEDIDENTITYENABLED'
339+
value: 'false'
340+
}
341+
{
342+
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_CLIENTID'
343+
value: ''
344+
}
345+
{{- end}}
328346
{{- if .Frontend}}
329347
{{- range $i, $e := .Frontend.Backends}}
330348
{
@@ -435,4 +453,7 @@ output AZURE_CACHE_REDIS_ID string = redis.outputs.resourceId
435453
{{- if .DbPostgres}}
436454
output AZURE_POSTGRES_FLEXIBLE_SERVER_ID string = postgreServer.outputs.resourceId
437455
{{- end}}
456+
{{- if .AzureEventHubs }}
457+
output AZURE_EVENT_HUBS_ID string = eventHubNamespace.outputs.resourceId
458+
{{- end}}
438459
{{ end}}

0 commit comments

Comments
 (0)