Gallery › App Service › Azure Community Policy
Deploy Webapp https only requirement
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.1.0
Deploy Webapp https only requirement
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 92 lines
{
"name": "ed859de9-4bc2-4b49-bce3-dc620ef610ec",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deploy Webapp https only requirement",
"description": "Deploy Webapp https only requirement",
"metadata": {
"version": "1.1.0",
"category": "App Service"
},
"mode": "All",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Web/sites"
},
{
"field": "Microsoft.Web/sites/httpsOnly",
"equals": false
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Web/sites",
"name": "[field('name')]",
"existenceCondition": {
"field": "Microsoft.Web/sites/httpsOnly",
"equals": true
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"webAppName": {
"type": "string"
},
"location": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"properties": {
"httpsOnly": true
}
}
]
},
"parameters": {
"webAppName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
}
}
}
}
}
}
}
}
}Bylawed859de9-4bc2-4b49-bce3-dc620ef610ec.bylaw.ps1 · 35 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'ed859de9-4bc2-4b49-bce3-dc620ef610ec' {
Properties @{
DisplayName = 'Deploy Webapp https only requirement'
Description = 'Deploy Webapp https only requirement'
Version = '1.1.0'
Category = 'App Service'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Web/sites' {
Require 'httpsOnly is not false' {
Field httpsOnly | Must -Not -Be $false -IfPresent
}
}
DeployIfNotExists 'Microsoft.Web/sites' -Role 'Website Contributor' -Name (Arm '[field(''name'')]') -Effect (Param Effect) {
Require 'httpsOnly is true' {
Field httpsOnly | Must -Be $true
}
Deployment -TemplateFile './templates/ed859de9-4bc2-4b49-bce3-dc620ef610ec.json' -Parameters ([ordered]@{
webAppName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
})
}
}Its deployment templates are written beside it:
templates/ed859de9-4bc2-4b49-bce3-dc620ef610ec.json
Source: policyDefinitions/App Service/deploy-webapp-https-only-requirement/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw