Created
September 3, 2019 17:25
-
-
Save wilfriedwoivre/8fc8040bbc655bd247de68e12e99f0e2 to your computer and use it in GitHub Desktop.
Azure Policy Auto Shutdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mode": "Indexed", | |
"policyRule": { | |
"if": { | |
"allOf": [ | |
{ | |
"field": "type", | |
"equals": "Microsoft.Compute/virtualMachines" | |
}, | |
{ | |
"field": "[concat('tags[', parameters('tagAutoShutdownEnabled'), ']')]", | |
"exists": "true" | |
}, | |
{ | |
"field": "[concat('tags[', parameters('tagAutoShutdownHour'), ']')]", | |
"exists": "true" | |
}, | |
{ | |
"field": "[concat('tags[', parameters('tagAutoShutdownTimeZone'), ']')]", | |
"exists": "true" | |
} | |
] | |
}, | |
"then": { | |
"effect": "deployIfNotExists", | |
"details": { | |
"type": "Microsoft.DevTestLab/schedules", | |
"name": "[concat('shutdown-computevm-', field('name'))]", | |
"existenceCondition": { | |
"allOf": [ | |
{ | |
"field": "tags.AutoShutdown-Enabled", | |
"equals": "[field('tags.AutoShutdown-Enabled')]" | |
}, | |
{ | |
"field": "tags.AutoShutdown-Hour", | |
"equals": "[field('tags.AutoShutdown-Hour')]" | |
}, | |
{ | |
"field": "tags.AutoShutdown-TimeZone", | |
"equals": "[field('tags.AutoShutdown-TimeZone')]" | |
} | |
] | |
}, | |
"roleDefinitionIds": [ | |
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c" | |
], | |
"deployment": { | |
"properties": { | |
"mode": "incremental", | |
"template": { | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"vmName": { | |
"type": "string" | |
}, | |
"location": { | |
"type": "string" | |
}, | |
"status": { | |
"type": "string", | |
"allowedValues": [ | |
"Enabled", | |
"Disabled" | |
] | |
}, | |
"shutdownHour": { | |
"type": "string" | |
}, | |
"timeZone": { | |
"type": "string" | |
} | |
}, | |
"variables": { | |
"shutdownHour": "[replace(parameters('shutdownHour'), ':', '')]" | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.DevTestLab/schedules", | |
"apiVersion": "2016-05-15", | |
"name": "[concat('shutdown-computevm-', parameters('vmName'))]", | |
"location": "[parameters('location')]", | |
"tags": { | |
"AutoShutdown-Enabled": "[parameters('status')]", | |
"AutoShutdown-TimeZone": "[parameters('timeZone')]", | |
"AutoShutdown-Hour": "[parameters('shutdownHour')]" | |
}, | |
"properties": { | |
"status": "[parameters('status')]", | |
"taskType": "ComputeVmShutdownTask", | |
"dailyRecurrence": { | |
"time": "[variables('shutdownHour')]" | |
}, | |
"timeZoneId": "[parameters('timeZone')]", | |
"notificationSettings": { | |
"status": "Disabled", | |
"timeInMinutes": 30 | |
}, | |
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]" | |
} | |
} | |
], | |
"outputs": { | |
"policy": { | |
"type": "string", | |
"value": "[concat('Autoshutdown configured for VM', parameters('vmName'))]" | |
} | |
} | |
}, | |
"parameters": { | |
"vmName": { | |
"value": "[field('name')]" | |
}, | |
"location": { | |
"value": "[field('location')]" | |
}, | |
"status": { | |
"value": "[field('tags.AutoShutdown-Enabled')]" | |
}, | |
"shutdownHour": { | |
"value": "[field('tags.AutoShutdown-Hour')]" | |
}, | |
"timeZone": { | |
"value": "[field('tags.AutoShutdown-TimeZone')]" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"parameters": { | |
"tagAutoShutdownEnabled": { | |
"type": "String", | |
"metadata": { | |
"displayName": "Tag Name", | |
"description": null | |
}, | |
"defaultValue": "AutoShutdown-Enabled" | |
}, | |
"tagAutoShutdownTimeZone": { | |
"type": "String", | |
"metadata": { | |
"displayName": "Tag Name", | |
"description": null | |
}, | |
"defaultValue": "AutoShutdown-TimeZone" | |
}, | |
"tagAutoShutdownHour": { | |
"type": "String", | |
"metadata": { | |
"displayName": "Tag Name", | |
"description": null | |
}, | |
"defaultValue": "AutoShutdown-Hour" | |
} | |
} | |
} |
il est possible de lancer le autoshutdown à un jour particulier de la semaine ? par exemple arrêter les machines tous les vendredi à une certaine heure
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Etant donné que l'autoscaling des webapp est une ressource à part entière, oui c'est envisageable de faire une policy en deployIfNotExits. Par contre attention, en terme de délai d'application de la policy il n'y a pas de SLA.
Voici le template ARM pour l'autoscaling : https://github.com/Azure/azure-quickstart-templates/blob/master/monitor-autoscale-webappserviceplan-simplemetricbased/azuredeploy.json