Gallery › SQL › Azure Community Policy
depoly-sql-managedinstance-shortterm-backup-retention-policy
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode All Version 1.0.0
need to add description
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 81 lines
{
"name": "b70ee2fa-2891-46b6-9cb3-79cedd37c781",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "depoly-sql-managedinstance-shortterm-backup-retention-policy",
"description": "need to add description",
"metadata": {
"version": "1.0.0",
"category": "SQL"
},
"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.Sql/managedInstances/databases"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Sql/managedInstances/databases/backupShortTermRetentionPolicies",
"name": "default",
"existenceCondition": {
"field": "Microsoft.Sql/managedInstances/databases/backupShortTermRetentionPolicies/retentionDays",
"equals": 35
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"fullDbName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Sql/managedInstances/databases/backupShortTermRetentionPolicies",
"apiVersion": "2020-11-01-preview",
"name": "[concat(parameters('fullDbName'), '/default')]",
"properties": {
"retentionDays": 35
}
}
]
},
"parameters": {
"fullDbName": {
"value": "[field('fullName')]"
}
}
}
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
]
}
}
}
}
}Bylawb70ee2fa-2891-46b6-9cb3-79cedd37c781.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'b70ee2fa-2891-46b6-9cb3-79cedd37c781' {
Properties @{
DisplayName = 'depoly-sql-managedinstance-shortterm-backup-retention-policy'
Description = 'need to add description'
Version = '1.0.0'
Category = 'SQL'
Mode = 'All'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Sql/managedInstances/databases'
DeployIfNotExists 'Microsoft.Sql/managedInstances/databases/backupShortTermRetentionPolicies' -Role 'Contributor' -Name 'default' -Effect (Param Effect) {
Require 'retentionDays is 35' {
Field retentionDays | Must -Be 35
}
Deployment -TemplateFile './templates/b70ee2fa-2891-46b6-9cb3-79cedd37c781.json' -Parameters ([ordered]@{
fullDbName = (Arm '[field(''fullName'')]')
})
}
}Its deployment templates are written beside it:
templates/b70ee2fa-2891-46b6-9cb3-79cedd37c781.json
Source: policyDefinitions/SQL/depoly-sql-managedinstance-shortterm-backup-retention-policy/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw