Skip to content

Instantly share code, notes, and snippets.

@marckean
Created November 4, 2018 10:01
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 marckean/75d736b9e190efba709756662573d8f2 to your computer and use it in GitHub Desktop.
Save marckean/75d736b9e190efba709756662573d8f2 to your computer and use it in GitHub Desktop.
{
"$connections": {
"value": {
"azureautomation": {
"connectionId": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/resourceGroups/OutlookApprovalLogic/providers/Microsoft.Web/connections/azureautomation",
"connectionName": "azureautomation",
"id": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/providers/Microsoft.Web/locations/australiaeast/managedApis/azureautomation"
},
"office365": {
"connectionId": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/resourceGroups/OutlookApprovalLogic/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/6bb00255-5486-4db1-96ca-5baefc18b0b2/providers/Microsoft.Web/locations/australiaeast/managedApis/office365"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_job": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureautomation']['connectionId']"
}
},
"method": "put",
"path": "/subscriptions/@{encodeURIComponent('6bb00255-5486-4db1-96ca-5baefc18b0b2')}/resourceGroups/@{encodeURIComponent('Marc-Automation')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('Marc-Automation')}/jobs",
"queries": {
"runbookName": "Get-All-VMs",
"wait": true,
"x-ms-api-version": "2015-10-31"
}
},
"runAfter": {},
"type": "ApiConnection"
},
"For_each": {
"actions": {
"Condition": {
"actions": {
"Create_job_2": {
"inputs": {
"body": {
"properties": {
"parameters": {
"VMnames": "@{items('For_each')['VMNames']}"
}
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['azureautomation']['connectionId']"
}
},
"method": "put",
"path": "/subscriptions/@{encodeURIComponent('6bb00255-5486-4db1-96ca-5baefc18b0b2')}/resourceGroups/@{encodeURIComponent('Marc-Automation')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('Marc-Automation')}/jobs",
"queries": {
"runbookName": "Stop-Azure-VMs-Parameter",
"wait": false,
"x-ms-api-version": "2015-10-31"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"expression": {
"or": [
{
"equals": [
"@body('Send_approval_email')?['SelectedOption']",
"Approve"
]
},
{
"equals": [
"@body('Send_approval_email')",
"@null "
]
}
]
},
"runAfter": {
"Send_approval_email": [
"Succeeded",
"TimedOut"
]
},
"type": "If"
},
"Send_approval_email": {
"inputs": {
"body": {
"Message": {
"Body": "Do you want to shut down @{items('For_each')['VMNames']} in @{items('For_each')['Environment']}?",
"Importance": "Normal",
"Options": "Approve, Reject",
"Subject": "Approval Request",
"To": "@items('For_each')['name']",
"UseOnlyHTMLMessage": false
},
"NotificationUrl": "@{listCallbackUrl()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"path": "/approvalmail/$subscriptions"
},
"limit": {
"timeout": "PT30M"
},
"runAfter": {},
"type": "ApiConnectionWebhook"
}
},
"foreach": "@body('Parse_JSON')",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_job_output": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureautomation']['connectionId']"
}
},
"method": "get",
"path": "/subscriptions/@{encodeURIComponent('6bb00255-5486-4db1-96ca-5baefc18b0b2')}/resourceGroups/@{encodeURIComponent('Marc-Automation')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent('Marc-Automation')}/jobs/@{encodeURIComponent(body('Create_job')?['properties']?['jobId'])}/output",
"queries": {
"x-ms-api-version": "2015-10-31"
}
},
"runAfter": {
"Create_job": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Parse_JSON": {
"inputs": {
"content": "@body('Get_job_output')",
"schema": {
"items": {
"properties": {
"Environment": {
"type": "string"
},
"VMNames": {
"type": "string"
},
"name": {
"type": "string"
}
},
"required": [
"name",
"VMNames",
"Environment"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"Get_job_output": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Day",
"interval": 1,
"schedule": {
"hours": [
"19"
]
},
"timeZone": "AUS Eastern Standard Time"
},
"type": "Recurrence"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment