Skip to content

Instantly share code, notes, and snippets.

@stefanstranger
Created March 3, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanstranger/2bf5d3e9b1628c282e68cab0ec004e38 to your computer and use it in GitHub Desktop.
Save stefanstranger/2bf5d3e9b1628c282e68cab0ec004e38 to your computer and use it in GitHub Desktop.
Logic App Workflow code for Running PowerShell in Azure Logic App Workflows
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HTTP_-_Create_Container_Group": {
"inputs": {
"authentication": {
"audience": "https://management.azure.com",
"type": "ManagedServiceIdentity"
},
"body": {
"location": "westeurope",
"properties": {
"containers": [
{
"name": "@{variables('var_ContainerName')}",
"properties": {
"command": [
"pwsh",
"/myscript.ps1",
"-Date:1/1",
"-OpenAIKey:@{variables('var_OpenAIKey')}"
],
"image": "@{variables('var_ImageName')}",
"resources": {
"requests": {
"cpu": 1,
"memoryInGB": 1.5
}
}
}
}
],
"imageRegistryCredentials": [
{
"password": "@{variables('var_ACRPassword')}",
"server": "<registryname>.azurecr.io",
"username": "<ACR Admin Account name>"
}
],
"osType": "Linux",
"restartPolicy": "Never"
},
"tags": {}
},
"method": "PUT",
"uri": "https://management.azure.com/subscriptions/@{variables('var_SubscriptionId')}/resourceGroups/@{variables('var_ResourceGroupName')}/providers/Microsoft.ContainerInstance/containerGroups/@{variables('var_ContainerName')}?api-version=2021-09-01"
},
"runAfter": {
"Initialize_variable_-_var_OpenAIKey": [
"Succeeded"
]
},
"type": "Http"
},
"Initialize_variable_-_var_ACRPassword": {
"inputs": {
"variables": [
{
"name": "var_ACRPassword",
"type": "string",
"value": "<Admin key for ACR>"
}
]
},
"runAfter": {
"Initialize_variable_-_var_ContainerName": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_Complete": {
"inputs": {
"variables": [
{
"name": "var_Complete",
"type": "boolean",
"value": "@false"
}
]
},
"runAfter": {
"HTTP_-_Create_Container_Group": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_ContainerName": {
"inputs": {
"variables": [
{
"name": "var_ContainerName",
"type": "string",
"value": "mycontainer"
}
]
},
"runAfter": {
"Initialize_variable_-_var_ResourceGroupName": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_ImageName": {
"inputs": {
"variables": [
{
"name": "var_ImageName",
"type": "string",
"value": "<registryname>.azurecr.io/myimage:latest"
}
]
},
"runAfter": {
"Initialize_variable_-_var_ACRPassword": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_OpenAIKey": {
"inputs": {
"variables": [
{
"name": "var_OpenAIKey",
"type": "string",
"value": "<OpenAI key>"
}
]
},
"runAfter": {
"Initialize_variable_-_var_ImageName": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_ResourceGroupName": {
"inputs": {
"variables": [
{
"name": "var_ResourceGroupName",
"type": "string",
"value": "logicapp-demo-rg"
}
]
},
"runAfter": {
"Initialize_variable_-_var_SubscriptionId": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_-_var_SubscriptionId": {
"inputs": {
"variables": [
{
"name": "var_SubscriptionId",
"type": "string",
"value": "c550db73-48f1-4a21-997f-ee415a4277eb"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@body('Get_logs_from_a_container_instance')?['content']",
"schema": {
"properties": {
"Date of Birth": {
"type": "string"
},
"Message": {
"type": "string"
},
"Person": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Until": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Until": {
"actions": {
"Condition": {
"actions": {
"Delay_-_10_seconds": {
"inputs": {
"interval": {
"count": 10,
"unit": "Second"
}
},
"runAfter": {},
"type": "Wait"
},
"Delete_a_container_group": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['aci']['connectionId']"
}
},
"method": "delete",
"path": "/subscriptions/@{encodeURIComponent(variables('var_SubscriptionId'))}/resourceGroups/@{encodeURIComponent(variables('var_ResourceGroupName'))}/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(variables('var_ContainerName'))}",
"queries": {
"x-ms-api-version": "2019-12-01"
}
},
"runAfter": {
"Get_logs_from_a_container_instance": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Get_logs_from_a_container_instance": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['aci']['connectionId']"
}
},
"method": "get",
"path": "/subscriptions/@{encodeURIComponent(variables('var_SubscriptionId'))}/resourceGroups/@{encodeURIComponent(variables('var_ResourceGroupName'))}/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(variables('var_ContainerName'))}/containers/@{encodeURIComponent(variables('var_ContainerName'))}/logs",
"queries": {
"x-ms-api-version": "2019-12-01"
}
},
"runAfter": {
"Delay_-_10_seconds": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Set_variable_-_var_Complete": {
"inputs": {
"name": "var_Complete",
"value": "@true"
},
"runAfter": {
"Delete_a_container_group": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"expression": {
"and": [
{
"equals": [
"@body('Get_properties_of_a_container_group')?['properties']?['provisioningState']",
"Succeeded"
]
}
]
},
"runAfter": {
"Get_properties_of_a_container_group": [
"Succeeded"
]
},
"type": "If"
},
"Get_properties_of_a_container_group": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['aci']['connectionId']"
}
},
"method": "get",
"path": "/subscriptions/@{encodeURIComponent(variables('var_SubscriptionId'))}/resourceGroups/@{encodeURIComponent(variables('var_ResourceGroupName'))}/providers/Microsoft.ContainerInstance/containerGroups/@{encodeURIComponent(variables('var_ContainerName'))}",
"queries": {
"x-ms-api-version": "2019-12-01"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": "@equals(variables('var_Complete'), true)",
"limit": {
"count": 60,
"timeout": "PT1H"
},
"runAfter": {
"Initialize_variable_-_var_Complete": [
"Succeeded"
]
},
"type": "Until"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"aci": {
"connectionId": "/subscriptions/<Azure Subscription Id>/resourceGroups/<Resource Group Name>/providers/Microsoft.Web/connections/aci",
"connectionName": "aci",
"connectionProperties": {
"authentication": {
"type": "ManagedServiceIdentity"
}
},
"id": "/subscriptions/<Azure Subscription Id>/providers/Microsoft.Web/locations/westeurope/managedApis/aci"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment