Bylaw

Gallery › Storage › Azure Community Policy

Upgrade GPv1 storage accounts to GPv2

Doesn't convert yet Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Audits or upgrades legacy General Purpose v1 (GPv1) storage accounts to General Purpose v2 (GPv2) while preserving the existing storage account redundancy SKU.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 101 lines
{
  "name": "d5a4e29c-8c1a-4d59-9f42-7b1b2f8a6e31",
  "mode": "Indexed",
  "displayName": "Upgrade GPv1 storage accounts to GPv2",
  "description": "Audits or upgrades legacy General Purpose v1 (GPv1) storage accounts to General Purpose v2 (GPv2) while preserving the existing storage account redundancy SKU.",
  "metadata": {
    "category": "Storage",
    "version": "1.0.0"
  },
  "parameters": {
    "effect": {
      "type": "String",
      "metadata": {
        "displayName": "Effect",
        "description": "Audit or automatically upgrade GPv1 storage accounts to GPv2."
      },
      "allowedValues": [
        "AuditIfNotExists",
        "DeployIfNotExists",
        "Disabled"
      ],
      "defaultValue": "AuditIfNotExists"
    }
  },
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Storage/storageAccounts"
        },
        {
          "field": "kind",
          "in": [
            "Storage",
            "StorageV2"
          ]
        }
      ]
    },
    "then": {
      "effect": "[parameters('effect')]",
      "details": {
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[field('name')]",
        "existenceCondition": {
          "field": "kind",
          "equals": "StorageV2"
        },
        "roleDefinitionIds": [
          "/providers/Microsoft.Authorization/roleDefinitions/17d1049b-9a84-46fb-8f53-869881c3d3ab"
        ],
        "deploymentScope": "resourceGroup",
        "deployment": {
          "properties": {
            "mode": "Incremental",
            "parameters": {
              "storageAccountName": {
                "value": "[field('name')]"
              },
              "location": {
                "value": "[field('location')]"
              },
              "skuName": {
                "value": "[field('Microsoft.Storage/storageAccounts/sku.name')]"
              }
            },
            "template": {
              "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "parameters": {
                "storageAccountName": {
                  "type": "string"
                },
                "location": {
                  "type": "string"
                },
                "skuName": {
                  "type": "string"
                }
              },
              "resources": [
                {
                  "type": "Microsoft.Storage/storageAccounts",
                  "apiVersion": "2023-01-01",
                  "name": "[parameters('storageAccountName')]",
                  "location": "[parameters('location')]",
                  "sku": {
                    "name": "[parameters('skuName')]"
                  },
                  "kind": "StorageV2",
                  "properties": {}
                }
              ]
            }
          }
        }
      }
    }
  }
}

Source: policyDefinitions/Storage/storage-account-upgrade-gpv1-storage-account-to-gpv2/azurepolicy.json in Azure/Community-Policy, under the MIT licence.