使用ARM模板/ powershell部署逻辑应用程序

时间:2016-05-15 18:20:20

标签: azure-resource-manager azure-logic-apps arm-template

如何部署调用SQL DB存储过程的逻辑应用程序?我尝试过以下行动。

    "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"
            }
          }

当我部署此模板时,会创建逻辑应用程序,但它会抛出错误,或者SQL Connection操作未显示在设计视图上。我在这做错了什么?用于调用当前arm支持的SQL Stored Proc的Logic App是什么?

3 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

我终于从@TusharJ链接中找到了这个,并且我发布了我在下面使用的模板来配置一个在特定时间间隔内调用SQL DB存储过程的LogicApp。

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]"
            }
          }
        }
      }
    }
  }
]

答案 2 :(得分:1)

自从上一个答案发布以来,API中的情况可能已经发生了变化。以下是截至2016年10月对我有用的内容。注意:我使用了很多变量的参数(定义未显示):

 {
  "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'))]"
  ]
}