Bylaw

Gallery › SQL › Azure Community Policy

deploy-hybrid-use-sql-mi

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 · 95 lines
{
  "name": "beec2258-b760-405a-9c75-afa06b54341a",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "deploy-hybrid-use-sql-mi",
    "description": "need to add description",
    "metadata": {
      "category": "SQL",
      "version": "1.0.0"
    },
    "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"
          },
          {
            "field": "Microsoft.Sql/managedInstances/licenseType",
            "notEquals": "BasePrice"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Sql/managedInstances",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
          ],
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Sql/managedInstances/licenseType",
                "Equals": "BasePrice"
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "sqlServerName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[parameters('sqlServerName')]",
                    "type": "Microsoft.Sql/managedInstances",
                    "apiVersion": "2018-06-01-preview",
                    "location": "[parameters('location')]",
                    "properties": {
                      "licenseType": "BasePrice"
                    }
                  }
                ]
              },
              "parameters": {
                "sqlServerName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    }
  }
}
Bylawbeec2258-b760-405a-9c75-afa06b54341a.bylaw.ps1 · 35 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'beec2258-b760-405a-9c75-afa06b54341a' {

    Properties @{
        DisplayName = 'deploy-hybrid-use-sql-mi'
        Description = 'need to add description'
        Category    = 'SQL'
        Version     = '1.0.0'
        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' {

        Require 'licenseType is BasePrice' {
            Field licenseType | Must -Be 'BasePrice'
        }
    }

    DeployIfNotExists 'Microsoft.Sql/managedInstances' -Role 'Owner' -Effect (Param Effect) {
        Require 'licenseType is BasePrice' {
            Field licenseType | Must -Be 'BasePrice'
        }
        Deployment -TemplateFile './templates/beec2258-b760-405a-9c75-afa06b54341a.json' -Parameters ([ordered]@{
                sqlServerName = (Arm '[field(''name'')]')
                location      = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/SQL/deploy-hybrid-use-sql-mi/azurepolicy.json in Azure/Community-Policy, under the MIT licence.