{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "storageName": "[concat(resourceGroup().name, 'storage')]",
    "serviceBusName": "[concat(resourceGroup().name, 'sb')]",
    "eventHubInputName": "[concat(resourceGroup().name, 'input')]",
    "eventHubEvalName": "[concat(resourceGroup().name, 'eval')]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageName')]",
      "apiVersion": "2015-06-15",
      "location": "[resourceGroup().location]",
      "properties": {
        "accountType": "Standard_LRS"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[concat(variables('serviceBusName'))]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[resourceGroup().location]",
      "kind": "Messaging",
      "sku": {
        "name": "Standard",
        "tier": "Standard",
        "capacity": 1
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "[concat(variables('serviceBusName'), '/', 'OwnerKey')]",
          "type": "Microsoft.ServiceBus/namespaces/authorizationRules",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', variables('serviceBusName'))]"
          ],
          "properties": {
            "KeyName": "OwnerKey",
            "ClaimType": "SharedAccessKey",
            "ClaimValue": "None",
            "Rights": [ "listen", "send", "manage" ],
            "Revision": -1
          }
        }
      ]
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[concat(variables('serviceBusName'), '/', variables('eventHubInputName'))]",
      "type": "Microsoft.ServiceBus/namespaces/eventHubs",
      "location": "[resourceGroup().location]",
      "properties": {
        "path": "[variables('eventHubInputName')]",
        "MessageRetentionInDays": 7,
        "PartitionCount": 2
      },
      "dependsOn": [
        "[concat('Microsoft.ServiceBus/namespaces/', variables('serviceBusName'))]"
      ],
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Manage",
          "type": "AuthorizationRules",
          "dependsOn": [
            "[concat(resourceId('Microsoft.ServiceBus/namespaces', variables('serviceBusName')), '/eventHubs/', variables('eventHubInputName'))]"
          ],
          "properties": {
            "keyName": "Manage",
            "claimType": "SharedAccessKey",
            "claimValue": "None",
            "rights": [ "Send", "Listen", "Manage" ]
          }
        }
      ]
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[concat(variables('serviceBusName'), '/', variables('eventHubEvalName'))]",
      "type": "Microsoft.ServiceBus/namespaces/eventHubs",
      "location": "[resourceGroup().location]",
      "properties": {
        "path": "[variables('eventHubEvalName')]",
        "MessageRetentionInDays": 7,
        "PartitionCount": 2
      },
      "dependsOn": [
        "[concat('Microsoft.ServiceBus/namespaces/', variables('serviceBusName'))]"
      ],
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Manage",
          "type": "AuthorizationRules",
          "dependsOn": [
            "[concat(resourceId('Microsoft.ServiceBus/namespaces', variables('serviceBusName')), '/eventHubs/', variables('eventHubEvalName'))]"
          ],
          "properties": {
            "keyName": "Manage",
            "claimType": "SharedAccessKey",
            "claimValue": "None",
            "rights": [ "Send", "Listen", "Manage" ]
          }
        }
      ]
    }
  ],
  "outputs": {
    "storageConnectionString": {
      "type": "string",
      "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageName')), '2015-06-15').key1)]"
    },
    "eventHubInputConnectionString": {
      "type": "string",
      "value": "[listkeys(resourceId('Microsoft.ServiceBus/namespaces/eventhubs/authorizationRules', variables('serviceBusName'), variables('eventHubInputName'), 'Manage'), '2015-08-01').primaryConnectionString]"
    },
    "eventHubEvalConnectionString": {
      "type": "string",
      "value": "[listkeys(resourceId('Microsoft.ServiceBus/namespaces/eventhubs/authorizationRules', variables('serviceBusName'), variables('eventHubEvalName'), 'Manage'), '2015-08-01').primaryConnectionString]"
    }
  }
}
