DEV Community

Leonard Soetedjo
Leonard Soetedjo

Posted on

7 3

Parameterising Logic App (Standard) connections.json with bicep - Part 2

Continuing from where we left off, the next step is to update the appsettings, and set connections.json to read from appsettings.

This is where it gets interesting. After lots of searching thru' the internet and testing, there are a couple of points to highlight:

  1. We can't replace the managedApiConnections information as a whole string, i.e. the below setting won't work

    ...
    
    "managedApiConnections": {
      "azureblob_1": {
        "api": {
          "id": "@appsetting('azureBlobApiId')"
        },
        "authentication": {
          "type": "ManagedServiceIdentity"
        },
        "connection": {
          "id": "@appsetting('azureBlobConnectionId')"
        },
        "connectionRuntimeUrl": "@appsetting('azureBlobConnectionRuntimeUrl')"
      }
    }
    ...
    

    With the above, our connections seems to be working. Looking at the API connections' status, it reports "Connected". All is well, it seems...until we try to save a workflow. When we try to save the workflow, we're shown a puzzling error:

    Workflow saved successfully. Workflow validation failed for the workflow 'xxxxxxxxxx'. The file 'connections.json' contains invalid expressions. The allowed expression functions are 'xxxxxxxxxx'.
    
  2. To workaround the above issue, we can find the hint from this doc Create cross-environment parameters for workflow inputs in Azure Logic Apps. In essence, rather than the above, we should instead create the following (the below code will still cause an error when saving a workflow. see step 3 for the last observation and workaround)

    ...
    
    "managedApiConnections": {
      "azureblob_1": {
        "api": {
          "id": "/subscriptions/@{appsetting('WORKFLOW_SUBSCRIPTION_ID')}/providers/Microsoft.Web/locations/@{appsetting('WORKFLOW_LOCATION')}/managedApis/azureblob"
        },
        "authentication": {
          "type": "ManagedServiceIdentity"
        },
        "connection": {
          "id": "/subscriptions/@{appsetting('WORKFLOW_SUBSCRIPTION_ID')}/resourceGroups/@{appsetting('WORKFLOW_RG_NAME')}/providers/Microsoft.Web/connections/azureblob"
        },
        "connectionRuntimeUrl": "@appsetting('azureBlobConnectionRuntimeUrl')"
      }
    }
    ...
    

    Note: only connectionRuntimeUrl can successfully use appsettings. apiId and connectionId can somehow be partially parameterised.

  3. Last observation, the above Microsoft doc recommendation for interpolated format by enclosing expression using curly brackets {} doesn't seem to work. In the end, we have to remove the curly brackets so that the final connections.json will look like this:

    ...
    
    "managedApiConnections": {
      "azureblob_1": {
        "api": {
          "id": "/subscriptions/@appsetting('WORKFLOW_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/@appsetting('WORKFLOW_LOCATION')/managedApis/azureblob"
        },
        "authentication": {
          "type": "ManagedServiceIdentity"
        },
        "connection": {
          "id": "/subscriptions/@appsetting('WORKFLOW_SUBSCRIPTION_ID')/resourceGroups/@appsetting('WORKFLOW_RG_NAME')/providers/Microsoft.Web/connections/azureblob"
        },
        "connectionRuntimeUrl": "@appsetting('azureBlobConnectionRuntimeUrl')"
      }
    }
    ...
    

Once the above settings are done, we're now able to make use of the API connections and save workflows successfully.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay