3

I have created azure logic app single tenant project using visual studio code by following this documentation. And then created workflow based on my requirement, this contains the data factory pipeline and send grid actions.

The workflow contains the hardcoded values in the create a pipeline run data factory action.

"Create_a_pipeline_run": {
            "inputs": {
                "host": {
                    "connection": {
                        "referenceName": "azuredatafactory_5"
                    }
                },
                "method": "post",
                "path": "/subscriptions/@{encodeURIComponent('xxxxxxx-xxxx-xxxx-xxxx-xxxxxx')}/resourcegroups/@{encodeURIComponent('xxxxx')}/providers/Microsoft.DataFactory/factories/@{encodeURIComponent('xxxxxx')}/pipelines/@{encodeURIComponent('xxxxxxx')}/CreateRun",
                "queries": {
                    "x-ms-api-version": "2017-09-01-preview"
                }
            },
            "runAfter": {},
            "type": "ApiConnection"
        },

And the connections.json file looks file below:

"managedApiConnections": {
"sendgrid": {
  "api": {
    "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/sendgrid"
  },
  "authentication": {
    "type": "ManagedServiceIdentity"
  }
},
"azuredatafactory_5": {
  "api": {
    "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/azuredatafactory"
  },
  "authentication": {
    "type": "ManagedServiceIdentity"
  }
}

}

The above managed API connections refers the existing API connections from azure. But I want to create the new managed API connections per environment (means parameterize the values in the connections.json file based on the environment).

Can anyone suggest me how to parameterize the values in workflow.json files per environment and parameterize the values in connections.json file per environment.

Pradeep
  • 5,101
  • 14
  • 68
  • 140

1 Answers1

4

A logic app standard is just an app service of kind workflowApp. You can heavily make use of appsettings here.

  1. Logic app parameters.

    In your workflow.json, you can use parameters like that:

    "Create_a_pipeline_run": {
      "inputs": {
        "host": {
          "connection": {
            "referenceName": "azuredatafactory_5"
          }
       },
       "method": "post",
       "path": "/subscriptions/@{encodeURIComponent(parameters('subscription_id'))}/resourcegroups/...",
       "queries": {
         "x-ms-api-version": "2017-09-01-preview"
       }
     },
     "runAfter": {},
     "type": "ApiConnection"
    }
    

    Then in your parameters.json file, reference app settings like that:

    {
      "subscription_id": {
        "type": "String",
        "value": "@appsetting('WORKFLOWS_SUBSCRIPTION_ID')"
      }
    }
    

    subscription_id must be defined as an app setting in the app service.

  2. Logic app connections. In the same way you can use app settings and parameters for connection information in your connections.json file:

    {
      "managedApiConnections": {
        "sendgrid": {
          "api": {
            "id": "/subscriptions/@appsetting('WORKFLOWS_SUBSCRIPTION_ID')/providers/Microsoft.Web/locations/centralus/managedApis/sendgrid"
          },
          ...
          "authentication": "@parameters('azure_authentication')"
        }
      }
    }
    

    then in your parameters.json file:

    {
      "azure_authentication": {
        "type": "object",
        "value": {
          "type": "ManagedServiceIdentity"
        }
      }
      ...
    }
    

This way you can easily offload all environment specific parameters to app settings

Thomas
  • 24,234
  • 6
  • 81
  • 125
  • Thanks @Thomas, If possible can you please update your answer with valid managed api connections for sendgrid and azure datafactory. – Pradeep Aug 23 '21 at 10:25
  • Thomas, can I create file named as `appsettings.json` in the project root folder for reading environment specific values? – Pradeep Aug 23 '21 at 10:27
  • 1
    you need to update the app settings in the app service itself (https://learn.microsoft.com/en-us/azure/app-service/configure-common) it can be done via automation in your pipeline – Thomas Aug 23 '21 at 10:30
  • Thomas, I have parameterized the workflow static values. But I'm not able to provision new managed api connections for sendgrid and datafactory by following the above answer. If possible, update your answer for to create the new managed api connection for sendgrid and datafactory. – Pradeep Aug 23 '21 at 17:03
  • New connection API are created using ARM/Bicep template not from the connections.json file. Coud you create separate questions for that and accep this answer if it answers the original post please ? – Thomas Aug 23 '21 at 20:02
  • Thomas, In the original post itself I have mentioned like `how to create the managed api connections for sendgrid and datafactory?` – Pradeep Aug 24 '21 at 05:20
  • The post is about parameterizing value in workflow and connections files, sorry but it will be too long for one answer and these are different questions as the connection api are created separately – Thomas Aug 24 '21 at 05:39
  • 1
    I have created another stack overflow question https://stackoverflow.com/questions/68906025/how-to-create-the-managed-api-connections-for-sendgrid-and-azure-datafactory – Pradeep Aug 25 '21 at 06:19