Skip to content

Knowledge Sharing

rujche edited this page Nov 20, 2024 · 6 revisions

1. How to create service-connector for DB like MySQL by in bicep file?

Problem

According to this page: Migrate an application to use passwordless connections with Azure Database for MySQL, after service connector created, it is still necessary to create a Microsoft Entra user for the managed identity and grant all permissions for the database. But the Microsoft.ServiceLinker/linkers can only be used to create service-connector, it can not create user in the DB.

Solution

When use Azure CLI command to create service-connector, it will create the required Microsoft Entra user in DB at the same time. And the bicep can use Microsoft.Resources/deploymentScripts to run the Azure CLI command. Here is an example PR.

Problems in "deploymentScripts"

Microsoft.Resources/deploymentScripts will only take effect for the first time. If run azd up for the second time, it will not run again because there is no change comparing to exist resources.

Solutions about problem in "deploymentScripts"

  1. Add forceUpdateTag in Microsoft.Resources/deploymentScripts. Here is an example commit.
  2. Use runOnce in avm/res/resources/deployment-script

2. Sometimes the environment variable not take effect in Spring Boot application.

Problem

For example: For property spring.cloud.azure.eventhubs.connection-string, SPRING_CLOUD_AZURE_EVENTHUBS_CONNECTION_STRING will take effect. But for property spring.cloud.azure.eventhubs.processor.checkpoint-store.connection-string, SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTION_STRING will not take effect.

Solution

Change environment variable to one of the following options:

  1. Option 1: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINTSTORE_CONNECTIONSTRING. This option removed all - in original property.
  2. Option 2: SPRING_CLOUD_AZURE_EVENTHUBS_PROCESSOR_CHECKPOINT_STORE_CONNECTION_STRING. This option changed all - in original property to _.
  3. Option 3: Use spring.cloud.azure.eventhubs.connection-string as environment variable name. It's suggested to use UPPER_CASE_WITH_UNDER_SCORE as environment name, but lower-case-with-dash is also supported. Service connector is using lower-case-with-dash now. In SJAD, we adopt this option.

NOTE

Option 1 is suggested according to Spring Boot's doc. And option 2 is legacy option which is supported now (In spring-boot:3.3), not sure if it will support forever.