{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "subnet": {
            "type": "string",
            "metadata": {
                "description": "The subnet to be used"
            }
        }
    },
    "variables": {
        "Contributor": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
        "location": "[resourceGroup().location]"
    },
    "resources": [
       {
            "type": "Microsoft.ManagedIdentity/userAssignedIdentities",
            "apiVersion": "2018-11-30",
            "location": "[variables('location')]",
            "name": "ray-msi-user-identity"
        },
        {
            "type": "Microsoft.Authorization/roleAssignments",
            "apiVersion": "2020-04-01-preview",
            "name": "[guid(resourceGroup().id)]",
            "properties": {
                "principalId": "[reference('ray-msi-user-identity').principalId]",
                "roleDefinitionId": "[variables('Contributor')]",
                "scope": "[resourceGroup().id]",
                "principalType": "ServicePrincipal"
            },
            "dependsOn": [
                "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'ray-msi-user-identity')]"
            ]
        },
        {
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2019-02-01",
            "name": "ray-nsg",
            "location": "[variables('location')]",
            "properties": {
                "securityRules": [
                    {
                        "name": "SSH",
                        "properties": {
                            "priority": 1000,
                            "protocol": "TCP",
                            "access": "Allow",
                            "direction": "Inbound",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*",
                            "destinationPortRange": "22"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2019-11-01",
            "name": "ray-vnet",
            "location": "[variables('location')]",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[parameters('subnet')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "ray-subnet",
                        "properties": {
                            "addressPrefix": "[parameters('subnet')]",
                            "networkSecurityGroup": {
                                "id": "[resourceId('Microsoft.Network/networkSecurityGroups','ray-nsg')]"
                              }
                        }
                    }
                ]
            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkSecurityGroups', 'ray-nsg')]"
            ]
        }
    ]
}