Deploying a logic app using ARM templates/powershell

送分小仙女□ 提交于 2019-12-30 11:18:10

问题


How can I Deploy a logic app that calls a SQL DB stored procedure? I've tried the following action.

    "actions": {
            "Execute_stored_procedure": {
              "conditions": [ ],
              "inputs": {
                "body": null,
                "host": {
                  "api": {
                    "runtimeUrl": "https://logic-apis-northcentralus.azure-apim.net/apim/sql"
                  },
                  "connection": {
                    "name": "<sql connection string>"
                  }
                },
                "method": "post",
                "path": "/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent(string('<stored-procedure-name>')))}"
              },
              "type": "apiconnection"
            }
          }

When I deploy this template, the logic app get's created but it's throwing errors or the SQL Connection action is not showing up on the design view. What am I doing wrong here? Is Logic App for calling SQL Stored Proc supported by arm currently?


回答1:


Here is a sample template for LogicApp ARM template + 'connections' resource
https://blogs.msdn.microsoft.com/logicapps/2016/02/23/deploying-in-the-logic-apps-preview-refresh/
https://github.com/jeffhollan/logicapps-deployments/blob/master/ftp_to_blob.json




回答2:


I've finally figured this out from @TusharJ links and I'm posting the template I've used below to configure a LogicApp that calls a SQL DB stored procedure in specific intervals.

resources:
[
  {
    "type": "Microsoft.Web/connections",
    "apiVersion": "2015-08-01-preview",
    "location": "[resourceGroup().location]",
    "name": "sqlconnector",
    "properties": {
      "api": {
        "id": "[concat('subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
      },
      "displayName": "sqlconnector",
      "parameterValues": {
        "sqlConnectionString": "<sql db connection string>"
      }
    }
  },
  {
    "type": "Microsoft.Logic/workflows",
    "apiVersion": "2015-08-01-preview",
    "name": "[parameters('logicAppName')]",
    "location": "[resourceGroup().location]",
    "tags": {
      "displayName": "LogicApp"
    },
    "properties": {
      "sku": {
        "name": "[parameters('workflowSkuName')]",
        "plan": {
          "id": "[concat(resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('svcPlanName'))]"
        }
      },
      "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2015-08-01-preview/workflowdefinition.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
          "$connections": {
            "defaultValue": { },
            "type": "Object"
          }
        },
        "triggers": {
          "recurrence": {
            "type": "recurrence",
            "recurrence": {
              "frequency": "Hour",
              "interval": 1
            }
          }
        },
        "actions": {
          "Execute_stored_procedure": {
            "conditions": [ ],
            "inputs": {
              "body": null,
              "host": {
                "api": {
                  "runtimeUrl": "[concat('https://logic-apis-', resourceGroup().location, '.azure-apim.net/apim/sql')]"
                },
                "connection": {
                  "name": "@parameters('$connections')['sql']['connectionId']"
                }
              },
              "method": "post",
              "path": "/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent(string('[dbo].[<Stored Proc Name>]')))}"
            },
            "type": "apiconnection"
          }
        },
        "outputs": { }
      },
      "parameters": {
        "$connections": {
          "value": {
            "sql": {
              "connectionId": "[resourceId('Microsoft.Web/connections', 'sqlconnector')]",
              "connectionName": "sqlconnector",
              "id": "[reference(concat('Microsoft.Web/connections/', 'sqlconnector'), '2015-08-01-preview').api.id]"
            }
          }
        }
      }
    }
  }
]



回答3:


Things may have changed in the API since the previous answer was given. Here is what worked for me as of 10/2016. Note: I used parameters (definitions not shown) for many of the variables:

 {
  "type": "Microsoft.Web/connections",
  "apiVersion": "2015-08-01-preview",
  "location": "[parameters('location')]",
  "name": "[variables('sql_conn_name')]",
  "properties": {
    "api": {
      "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
    },
    "displayName": "sql_connection",
    "parameterValues": {
      "server": "[concat(variables('dbserver_unique_name'), '.database.windows.net')]",
      "database": "[parameters('databases_name')]",
      "authType": "windows",
      "username": "[parameters('databases_admin_user')]",
      "password": "[parameters('databases_admin_password')]"
    }
  }
}, 
{
  "type": "Microsoft.Logic/workflows",
  "name": "[variables('logic_app_name')]",
  "apiVersion": "2016-06-01",
  "location": "[parameters('location')]",
  "properties": {
    "state": "Enabled",
    "definition": {
      "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "$connections": {
          "defaultValue": { },
          "type": "Object"
        }
      },
      "triggers": {
        "Recurrence": {
          "recurrence": {
            "frequency": "Hour",
            "interval": 1
          },
          "type": "Recurrence"
        }
      },
      "actions": {
        "Execute_stored_procedure": {
          "runAfter": { },
          "type": "ApiConnection",
          "inputs": {
            "body": {
              "timeoffset": "-4"
            },
            "host": {
              "api": {
                "runtimeUrl": "[concat('https://logic-apis-', parameters('location'), '.azure-apim.net/apim/sql')]"
              },
              "connection": {
                "name": "@parameters('$connections')['sql']['connectionId']"
              }
            },
            "method": "post",
            "path": "/datasets/default/procedures/@{encodeURIComponent(encodeURIComponent('[dbo].[usp_UpdateHourlyOos]'))}"
          }
        }
      },
      "outputs": { }
    },
    "parameters": {
      "$connections": {
        "value": {
          "sql": {
            "connectionId": "[concat(subscription().id, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/connections/', variables('sql_conn_name'))]",
            "connectionName": "[variables('sql_conn_name')]",
            "id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
          }
        }
      }
    }
  },
  "resources": [ ],
  "dependsOn": [
    "[resourceId('Microsoft.Web/connections', variables('sql_conn_name'))]"
  ]
}


来源:https://stackoverflow.com/questions/37242019/deploying-a-logic-app-using-arm-templates-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!