{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.41.2.15936",
      "templateHash": "14592899633732085177"
    },
    "description": "EasyLife 365, identity/credential-renewal-secret v1: a key vault with Azure role-based access control and a secret. For a new vault only. Give access with the grant script afterwards."
  },
  "parameters": {
    "vaultName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 24,
      "metadata": {
        "description": "The key vault: 3 to 24 letters, digits and hyphens, starting with a letter, ending with a letter or digit, with no two hyphens in a row. Unique in Azure."
      }
    },
    "secretName": {
      "type": "string",
      "minLength": 1,
      "maxLength": 127,
      "metadata": {
        "description": "The secret: 1 to 127 letters, digits and hyphens."
      }
    },
    "region": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The Azure region of the key vault. Default: the region of the resource group."
      }
    },
    "secretValue": {
      "type": "securestring",
      "defaultValue": "[newGuid()]",
      "metadata": {
        "description": "The first value of the secret. Leave the default: a random value that nobody sees. EasyLife 365 replaces it when it renews the credential."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.KeyVault/vaults",
      "apiVersion": "2023-07-01",
      "name": "[parameters('vaultName')]",
      "location": "[parameters('region')]",
      "properties": {
        "tenantId": "[subscription().tenantId]",
        "sku": {
          "family": "A",
          "name": "standard"
        },
        "enableRbacAuthorization": true,
        "enableSoftDelete": true,
        "softDeleteRetentionInDays": 90,
        "accessPolicies": []
      }
    },
    {
      "type": "Microsoft.KeyVault/vaults/secrets",
      "apiVersion": "2023-07-01",
      "name": "[format('{0}/{1}', parameters('vaultName'), parameters('secretName'))]",
      "properties": {
        "value": "[parameters('secretValue')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.KeyVault/vaults', parameters('vaultName'))]"
      ]
    }
  ],
  "outputs": {
    "secretResourceId": {
      "type": "string",
      "value": "[resourceId('Microsoft.KeyVault/vaults/secrets', parameters('vaultName'), parameters('secretName'))]"
    }
  }
}