arm-artifacts/shared-templates/key-vault.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "tenantId": {
      "type": "string",
      "defaultValue": "[subscription().tenantId]",
      "metadata": {
        "description": "Tenant ID for the subscription and use assigned access to the vault."
      }
    },
    "keyVaultName": {
      "type": "string",
      "metadata": {
        "description": "Name of the vault"
      }
    },
    "keyVaultSku": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [
        "Standard",
        "Premium"
      ],
      "metadata": {
        "description": "SKU for the vault"
      }
    },
    "accessPolicies": {
      "type": "array",
      "defaultValue": [],
      "metadata": {
        "description": "Access policies for the vault."
      }
    },
    "diagnosticsStorageAccountName": {
      "type": "string",
      "metadata": {
        "description": "The storage account to use for diagnostics"
      }
    },
    "diagnosticsRetentionDays": {
      "type": "int",
      "defaultValue": 30,
      "metadata": {
        "description": "The number of day to retain logs for"
      }
    },
    "diagnosticsEnabled": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Flag indicating whether diagnostics are enabled or not"
      }
    },
    "tagValues": {
      "type": "object",
      "defaultValue": {}
    }
  },
  "variables": {
    "defaultApiVersion": "2015-06-15",
    "location": "[resourceGroup().location]",
    "keyVaultLocalTags": {
      "displayName": "KeyVault"
    }
  },
  "resources": [
    {
      "type": "Microsoft.KeyVault/vaults",
      "name": "[parameters('keyVaultName')]",
      "apiVersion": "2015-06-01",
      "location": "[resourceGroup().location]",
      "tags": "[union(parameters('tagValues'), variables('keyVaultLocalTags'))]",
      "properties": {
        "tenantId": "[parameters('tenantId')]",
        "accessPolicies": "[parameters('accessPolicies')]",
        "sku": {
          "name": "[parameters('keyVaultSku')]",
          "family": "A"
        }
      },
      "resources": [
        {
          "type": "providers/diagnosticSettings",
          "name": "Microsoft.Insights/service",
          "dependsOn": [
            "[resourceId('Microsoft.KeyVault/vaults', parameters('keyVaultName'))]"
          ],
          "apiVersion": "2015-07-01",
          "properties": {
            "storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('diagnosticsStorageAccountName'))]",
            "logs": [
              {
                "category": "AuditEvent",
                "enabled": "[parameters('diagnosticsEnabled')]",
                "retentionPolicy": {
                  "days": "[parameters('diagnosticsRetentionDays')]",
                  "enabled": true
                }
              }
            ]
          }
        }
      ]
    }
  ],
  "outputs": {
  }
}