Skip to content

Commit

Permalink
Support detect Azure Event Hubs: produce message only. Try to connect…
Browse files Browse the repository at this point in the history
… by connection string, but failed: Cant not get connection string. Issue created: Azure/bicep-registry-modules#3638
  • Loading branch information
rujche committed Oct 25, 2024
1 parent 41cc716 commit b5d6dee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cli/azd/resources/scaffold/templates/main.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ output AZURE_CACHE_REDIS_ID string = resources.outputs.AZURE_CACHE_REDIS_ID
{{- if .DbPostgres}}
output AZURE_POSTGRES_FLEXIBLE_SERVER_ID string = resources.outputs.AZURE_POSTGRES_FLEXIBLE_SERVER_ID
{{- end}}
{{- if .AzureEventHubs }}
output AZURE_EVENT_HUBS_ID string = resources.outputs.AZURE_EVENT_HUBS_ID
{{- end}}
{{ end}}
35 changes: 28 additions & 7 deletions cli/azd/resources/scaffold/templates/resources.bicept
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,23 @@ module postgreServer 'br/public:avm/res/db-for-postgre-sql/flexible-server:0.1.4
}
}
{{- end}}
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
{{- if .AzureEventHubs }}

module eventHubs 'br/public:avm/res/event-hub/namespace:0.7.1' = {
name: 'eventHubs'
module eventHubNamespace 'br/public:avm/res/event-hub/namespace:0.7.1' = {
name: 'eventHubNamespace'
params: {
name: '${abbrs.eventHubNamespaces}${resourceToken}'
location: location
roleAssignments: [
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
{{- range .Services}}
{
principalId: {{bicepName .Name}}Identity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'f526a384-b230-433a-b45c-95f59c4a2dec')
}
{{- end}}
{{- end}}
]
eventhubs: [
{{- range $eventHubName := .AzureEventHubs.EventHubNames}}
Expand Down Expand Up @@ -307,15 +309,17 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
secretRef: 'redis-pass'
}
{{- end}}
{{- if .AzureEventHubs }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_NAMESPACE'
value: eventHubNamespace.outputs.name
}
{{- end}}
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingManagedIdentity) }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
value: ''
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_NAMESPACE'
value: eventHubs.outputs.name
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_MANAGEDIDENTITYENABLED'
value: 'true'
Expand All @@ -325,6 +329,20 @@ module {{bicepName .Name}} 'br/public:avm/res/app/container-app:0.8.0' = {
value: {{bicepName .Name}}Identity.outputs.clientId
}
{{- end}}
{{- if (and .AzureEventHubs .AzureEventHubs.AuthUsingConnectionString) }}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING'
value: listKeys('${eventHubNamespace.outputs.resourceId}/AuthorizationRules/RootManageSharedAccessKey', '2024-01-01').primaryConnectionString # Issue: https://github.com/Azure/bicep-registry-modules/issues/3638
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_MANAGEDIDENTITYENABLED'
value: 'false'
}
{
name: 'SPRING_CLOUD_AZURE_EVENTHUBS_CREDENTIAL_CLIENTID'
value: ''
}
{{- end}}
{{- if .Frontend}}
{{- range $i, $e := .Frontend.Backends}}
{
Expand Down Expand Up @@ -435,4 +453,7 @@ output AZURE_CACHE_REDIS_ID string = redis.outputs.resourceId
{{- if .DbPostgres}}
output AZURE_POSTGRES_FLEXIBLE_SERVER_ID string = postgreServer.outputs.resourceId
{{- end}}
{{- if .AzureEventHubs }}
output AZURE_EVENT_HUBS_ID string = eventHubNamespace.outputs.resourceId
{{- end}}
{{ end}}

0 comments on commit b5d6dee

Please sign in to comment.