@@ -65,23 +65,20 @@ param existingFabricCapacityName string = ''
6565
6666// ============================================================================
6767// Determine whether to use existing resources
68- // Scenarios:
69- // 1. Create new namespace + new event hub: existingEventHubNamespaceId not set
70- // 2. Use existing namespace, create new event hub: existingEventHubNamespaceId is set
71- //
72- // NOTE: A new Event Hub is always created to avoid mixing unrelated event types.
73- // This follows best practices for Event Hub usage.
7468// ============================================================================
7569
76- var useExistingEventHubNamespace = !empty (existingEventHubNamespaceId )
77- // Extract namespace name from resource ID if using existing, otherwise generate new name
78- var eventHubNamespaceNameFromId = useExistingEventHubNamespace ? last (split (existingEventHubNamespaceId , '/' )) : ''
79- // Parse subscription ID and resource group from the namespace resource ID
80- // This enables cross-subscription and cross-resource-group deployments
81- // Example: namespace in sub-123/rg-shared while deploying to sub-456/rg-demo
82- var eventHubNamespaceSubscriptionId = useExistingEventHubNamespace ? split (existingEventHubNamespaceId , '/' )[2 ] : ''
83- var eventHubNamespaceResourceGroup = useExistingEventHubNamespace ? split (existingEventHubNamespaceId , '/' )[4 ] : ''
84- var useExistingFabricCapacity = !empty (existingFabricCapacityName )
70+ // Use an existing namespace if a valid resource ID is provided; otherwise create a new one.
71+ // A new Event Hub is always created to avoid mixing unrelated event types.
72+ var useExistingEventHubNamespace = startsWith (existingEventHubNamespaceId , '/subscriptions/' )
73+ // Fallback placeholder ensures split() is always called on a well-formed resource ID.
74+ var _safeEventHubNamespaceId = useExistingEventHubNamespace
75+ ? existingEventHubNamespaceId
76+ : '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/placeholder/providers/Microsoft.EventHub/namespaces/placeholder'
77+ var eventHubNamespaceNameFromId = last (split (_safeEventHubNamespaceId , '/' ))
78+ var eventHubNamespaceSubscriptionId = split (_safeEventHubNamespaceId , '/' )[2 ]
79+ var eventHubNamespaceResourceGroup = split (_safeEventHubNamespaceId , '/' )[4 ]
80+ // Use an existing Fabric capacity if a valid name is provided; otherwise create a new one.
81+ var useExistingFabricCapacity = !empty (existingFabricCapacityName ) && !startsWith (existingFabricCapacityName , '$' )
8582
8683var solutionSuffix = toLower (trim (replace (
8784 replace (
0 commit comments