Bylaw

Gallery › Storage › Azure Community Policy

enforce-StorageAccount-NamingConvention

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

The purpose of this policy is to deny the creation of storage accounts that do not meet the set naming convention listed in CAF.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONazurepolicy.json · 53 lines
{
  "name": "20d6d7e4-8ac6-44a1-be41-494573727b55",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "enforce-StorageAccount-NamingConvention",
    "description": "The purpose of this policy is to deny the creation of storage accounts that do not meet the set naming convention listed in CAF.",
    "metadata": {
      "category": "Storage",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "field": "name",
            "notContains": "st"
          },
          {
            "field": "name",
            "notContains": "stdiag"
          },
          {
            "field": "name",
            "notContains": "share"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw20d6d7e4-8ac6-44a1-be41-494573727b55.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '20d6d7e4-8ac6-44a1-be41-494573727b55' {

    Properties @{
        DisplayName = 'enforce-StorageAccount-NamingConvention'
        Description = 'The purpose of this policy is to deny the creation of storage accounts that do not meet the set naming convention listed in CAF.'
        Category    = 'Storage'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Deny', 'Audit', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'Deny, Audit or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

        When {
            Field name | Must -Not -ContainText 'st'
            Field name | Must -Not -ContainText 'stdiag'
        }

        Require 'name contains share' {
            Field name | Must -ContainText 'share'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Storage/enforce-storageaccount-namingconvention/azurepolicy.json in Azure/Community-Policy, under the MIT licence.