While configuring some App Services with Bicep, I also had the need to add Diagnostic Settings. At the time could not find any good posts describing this, so here is how I solved it.

As we most often create Log Analytics Workspace in a different repo than the App Services, we reference an existing Log Analytics Workspace, and also add some logic to check where the Log Analytics Workspace name has been specified or not.
If the “logAnalyticsWorkspaceName” parameter is empty, it will not attempt to add the Diagnostic Settings.

Reference: https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/2017-05-01-preview/diagnosticsettings?pivots=deployment-language-bicep