{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmSku": {
      "type": "string",
      "defaultValue": "Standard_A4",
      "metadata": {
        "description": "Size of VMs in the VM Scale Set."
      }
    },
    "clusterName": {
      "type": "string",
      "metadata": {
        "description": "String used as a base for naming resources. Must be 3-61 characters in length and globally unique across Azure. A hash is prepended to this string for some resources, and resource-specific information is appended."
      },
      "maxLength": 61
    },
    "nodeCount": {
      "type": "int",
      "defaultValue": 2,
      "minValue": 1,
      "metadata": {
        "description": "Number of VM instances (100 or less) for member artifactory nodes. Minimum 1 node."
      },
      "maxValue": 100
    },
    "artifactoryVersion": {
      "type": "string",
      "defaultValue": "6.2.0",
      "metadata": {
        "description": "Artifactory version to deploy. Supported from 5.8.0 and above."
      }
    },
    "masterKey": {
      "type": "string",
      "defaultValue": "1ce2be4490ca2c662cb79636cf9b7b8e",
      "metadata": {
        "description": "Master key for Artifactory cluster. Generate master.key using command '$openssl rand -hex 16'"
      },
      "maxLength": 64
    },
    "adminUsername": {
      "type": "string",
      "metadata": {
        "description": "Admin username on all VMs. Follow conventions for azure VM admin user name."
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "Admin password on all VMs. Follow conventions for azure VM admin password rules."
      }
    },
    "ubuntuOSVersion": {
      "type": "string",
      "defaultValue": "16.04.0-LTS",
      "allowedValues": [
        "12.04.5-LTS",
        "14.04.2-LTS",
        "16.04.0-LTS"
      ],
      "metadata": {
        "description": "The Ubuntu version for the VM."
      }
    },
    "artifactoryLicense1": {
      "type": "string",
      "metadata": {
        "description": "Artifactory Enterprise License. Providing one license is mandatory"
      }
    },
    "artifactoryLicense2": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Artifactory Enterprise License"
      }
    },
    "artifactoryLicense3": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Artifactory Enterprise License"
      }
    },
    "artifactoryLicense4": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Artifactory Enterprise License"
      }
    },
    "artifactoryLicense5": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Artifactory Enterprise License"
      }
    },
    "certificate": {
      "type": "string",
      "defaultValue": "-----BEGIN CERTIFICATE----- MIIFhzCCA2+gAwIBAgIJALC4r5BQWZE4MA0GCSqGSIb3DQEBCwUAMFoxCzAJBgNV BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRMwEQYDVQQHDApTYW50YUNsYXJh MQswCQYDVQQKDAJJVDEUMBIGA1UEAwwLKi5sb2NhbGhvc3QwHhcNMTgwMTE3MTk0 NjI4WhcNMTkwMTA4MTk0NjI4WjBaMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2Fs aWZvcm5pYTETMBEGA1UEBwwKU2FudGFDbGFyYTELMAkGA1UECgwCSVQxFDASBgNV BAMMCyoubG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA 7KfOWDQlov8cMa8r/lcJqiWZaH9myQC74Vbe0HXsntQbcvljkjG2P7ebm5dd9Bzc sauNOJpbKf5AhFK1iwJUAkciGc1LR4k8wfWmQM3NPS8hrqrtH20zqNpdFRpNYjja JofwccPNm030GhhZkZ95TpruvmswMDwspl3jfqdcc/eiQsHcKyGnV2a+UAeoqe7J mHhmhRy1MLqAjF5U1GrUYUONA+22iRDJb4c9B91QoWvsnXpdA9NKV/mmA3/rIdx6 Ld2IPRdrIw2K5sAnXsh3bx2oCSvSfussf0x+4XDrnsaHVfjwvfNL8ECOuac2Oi/E WOp9528gOohpFAuwEt63Vl5p8/CC9m0HJDTZBKm2l5eD1kdPIj4PvP9Sn9CxGXKQ E1bxWoFxGX8EyRW0b0NK31N7b8JPZ1SoFNiB5amOMNLvR26a7cQrKumTuJeYK9Ja JaxhMXM7R0DA0Ev8ZG2xmyCygox+1KPSmJOIEpT70BFbj3rKLNqP22ET+zvPuh+2 DdgyrpHFeYkGWjMbWPjK7wJsD2zM8ccoJQfepPz8I4rT0JfrKAQgCGuGOggneaNJ KTVGNOFbj5AXdZ/Q+GvNommyRdq4J7EnqY6L+P25fo5qZ6UZ/iS0tPcvxgn0Fdhs pUPbQyQIDZyxZd3Q1lUIE38ol8P66mS2zbzf8EeOCoUCAwEAAaNQME4wHQYDVR0O BBYEFETAQM/5P7XJ8kevHFj6BPndQOFaMB8GA1UdIwQYMBaAFETAQM/5P7XJ8kev HFj6BPndQOFaMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAJ1TepKv LWYhFmVQcgZwZf/qt1a1cohzJSm6da9RCnnAWC7WC/U117bgSomtrH1v0OysHFhB zBBUeBqI7+OmzAX8dhj+roKkcnFUM/IwlK1eueIIA//CWvEf/o0XExilVS2yCc9d PTpOQBXwk9QinxK36kHdBiGxa7dW0JPnOEEmuMgGORKeLy4J6Ik8iSeFY1SZVcOI +6WWvoKciPlmIeccC+6YVmkeBwhP2o5r5w/UAaO2hSnGvmm4UIj/VJv4VQu7xTUp cIfFz5NtIr80DbqcyPiEMS2ETJ4L/kO4MS5FfeEXyQuXCzmiIDVY6tE3C7+kZmK4 JzPLuWm9ndQoyQySOGfQqvlUR1+YxUdvmu3LrOS5dOA354Q36wHa4wEGUoHU/7GV fYQmmmDSDaNSpXW5PFey6scFyDBS/yYJ0H9EjYb/11HeWYj8Yv5xTWj8nhzJONC8 D6Y5ydlU4PifM2pOf88pTYpmogNwLJWXbql5I9cvMa8APo4yLVqcISU5ynsvFke+ Non+T0mHpJai/hrA9NK+s6EGC1dAX58jy61h6FhOPI1d4s/mov/KMa2t3SfZp5SF 81aR6dHvO56teiK5M1xMkrqG75zh3TMFJJLRFe9XxeB4JeN76URB3mgADOUqkBxd ibSgVqfKwOw4IujEcqMUc5mqSnbLY1Dv+oby -----END CERTIFICATE-----",
      "metadata": {
        "description": "To use Artifactory as docker registry you need to provide wild card valid Certificate. Provide your SSL Certificate."
      }
    },
    "certificateKey": {
      "type": "string",
      "defaultValue": "-----BEGIN PRIVATE KEY----- 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 S+j1+iUKGGhwVmhqh75q5do3+VF3XlAh -----END PRIVATE KEY-----",
      "metadata":  {
        "description": "Provide your SSL Certificate key"
      }
    },
    "certificateDomain": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "artifactory",
      "metadata":  {
        "description": "Provide your Certificate Domain Name. For e.g jfrog.team for certificate with *.jfrog.team"
      }
    },
    "artifactoryServerName": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "artifactory",
      "metadata":  {
        "description": "Provide artifactory server name to be used in Nginx. e.g artifactory for artifactory.jfrog.team"
      }
    },
    "extraJavaOptions": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "-server -Xms2g -Xmx12g -Xss256k -XX:+UseG1GC -XX:OnOutOfMemoryError=\\\"kill -9 %p\\\"",
      "metadata":  {
        "description": "Setting Java Memory Parameters for Artifactory. Learn about system requirements for Artifactory https://www.jfrog.com/confluence/display/RTF/System+Requirements#SystemRequirements-RecommendedHardware."
      }
    },
    "DB_Admin_User": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "artifactory",
      "metadata": {
        "description": "Database Admin user name"
      }
    },
    "DB_Admin_Password": {
      "type": "securestring",
      "minLength": 1,
      "defaultValue": "jFrog123",
      "metadata": {
        "description": "Database Admin password"
      }
    },
    "DB_Name": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "artdb",
      "metadata": {
        "description": "Database name"
      }
    },
    "DB_Edition": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "Basic",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "metadata": {
        "description": "Database Edition"
      }
    },
    "DB_Location": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Database location. Default to resource group location if blank."
      }
    },
    "_artifactsLocation": {
      "type": "string",
      "metadata": {
        "description": "The base URI where artifacts required by this template are located. When the template is deployed using the accompanying scripts, a private location in the subscription will be used and this value will be automatically generated."
      },
      "defaultValue": "https://raw.githubusercontent.com/JFrogDev/JFrog-Cloud-Installers/master/AzureResourceManager/"
    },
    "_artifactsLocationSasToken": {
      "type": "securestring",
      "metadata": {
        "description": "The sasToken required to access _artifactsLocation.  When the template is deployed using the accompanying scripts, a sasToken will be automatically generated."
      },
      "defaultValue": ""
    }
  },
  "variables": {
    "namingInfix": "[toLower(substring(concat(parameters('clusterName'), uniqueString(resourceGroup().id)), 0, 9))]",
    "addressPrefix": "10.0.0.0/16",
    "subnetPrefix": "10.0.1.0/24",
    "virtualNetworkName": "[concat(variables('namingInfix'), 'vnet')]",
    "subnetName": "[concat(variables('namingInfix'), 'subnet')]",
    "scaleSetName": "[concat(variables('namingInfix'), 'scaleset')]",
    "lbName": "[concat(variables('namingInfix'), 'lb')]",
    "bepoolName": "[concat(variables('lbName'), 'bepool')]",
    "fepoolName": "[concat(variables('lbName'), 'fepool')]",
    "lbID": "[resourceId('Microsoft.Network/loadBalancers',variables('lbName'))]",
    "bepoolID": "[concat(variables('lbID'),'/backendAddressPools/', variables('bepoolName'))]",
    "feIpConfigName": "[concat(variables('fepoolName'), 'IpConfig')]",
    "feIpConfigId": "[concat(variables('lbID'),'/frontendIPConfigurations/', variables('feIpConfigName'))]",
    "pipName": "[concat(variables('namingInfix'), 'pip')]",
    "nicName": "[concat(variables('namingInfix'), 'nic')]",
    "natPoolName": "[concat(variables('lbName'), 'natpool')]",
    "ipConfigName": "[concat(variables('namingInfix'), 'ipconfig')]",
    "httpProbeName": "httpProbe",
    "httpsProbeName": "httpsProbe",
    "storageAccountName": "[concat(variables('namingInfix'), 'storage')]",
    "storageAccountType": "Standard_LRS",
    "vmStorageAccountContainerName": "filestore",
    "azureSqlServerName": "[concat(variables('namingInfix'), 'sqlsrv')]",
    "DB_Name": "[parameters('DB_Name')]",
    "DB_Admin_User": "[parameters('DB_Admin_User')]",
    "DB_Admin_Password": "[parameters('DB_Admin_Password')]",
    "DB_Edition": "[parameters('DB_Edition')]",
    "DB_Location": "[parameters('DB_Location')]",
    "artifactoryVersion": "[parameters('artifactoryVersion')]",
    "masterKey": "[parameters('masterKey')]",
    "certificate": "[parameters('certificate')]",
    "certificateKey": "[parameters('certificateKey')]",
    "certificateDomain": "[parameters('certificateDomain')]",
    "artifactoryServerName": "[parameters('artifactoryServerName')]",
    "extraJavaOptions": "[parameters('extraJavaOptions')]",
    "artifactoryLicense1": "[parameters('artifactoryLicense1')]",
    "artifactoryLicense2": "[parameters('artifactoryLicense2')]",
    "artifactoryLicense3": "[parameters('artifactoryLicense3')]",
    "artifactoryLicense4": "[parameters('artifactoryLicense4')]",
    "artifactoryLicense5": "[parameters('artifactoryLicense5')]",
    "osType": {
      "publisher": "Canonical",
      "offer": "UbuntuServer",
      "sku": "[parameters('ubuntuOSVersion')]",
      "version": "latest"
    },
    "apiVersion": "2015-06-15",
    "imageReference": "[variables('osType')]",
    "dbTemplate": "azureDBDeploy.json",
    "dbTemplateLocation": "[concat(parameters('_artifactsLocation'), 'nested', '/', variables('dbTemplate'))]",
    "nsgName": "[concat(variables('namingInfix'), 'nsg')]"
  },
  "resources": [
    {
      "type": "Microsoft.Network/networkSecurityGroups",
      "location": "[resourceGroup().location]",
      "properties": {
        "securityRules": [
          {
            "name": "ssh-rule",
            "properties": {
              "description": "Allow SSH",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "22",
              "sourceAddressPrefix": "Internet",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 100,
              "direction": "Inbound"
            }
          },
          {
            "name": "http-rule",
            "properties": {
              "description": "Allow HTTP",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "8081",
              "sourceAddressPrefix": "Internet",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 101,
              "direction": "Inbound"
            }
          },
          {
            "name": "http-rule-1",
            "properties": {
              "description": "Allow HTTP",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "80",
              "sourceAddressPrefix": "Internet",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 102,
              "direction": "Inbound"
            }
          },
          {
            "name": "https-rule",
            "properties": {
              "description": "Allow HTTP",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "443",
              "sourceAddressPrefix": "Internet",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 103,
              "direction": "Inbound"
            }
          },
          {
            "name": "membership-rule",
            "properties": {
              "description": "Allow HTTP",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "10001",
              "sourceAddressPrefix": "Internet",
              "destinationAddressPrefix": "*",
              "access": "Allow",
              "priority": 105,
              "direction": "Inbound"
            }
          }
        ]
      },
      "name": "[variables('nsgName')]",
      "apiVersion": "2016-03-30"
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[variables('virtualNetworkName')]",
      "location": "[resourceGroup().location]",
      "apiVersion": "2016-03-30",
      "dependsOn": [
        "[concat('Microsoft.Network/networkSecurityGroups/', variables('nsgName'))]"
      ],
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('addressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('subnetName')]",
            "properties": {
              "addressPrefix": "[variables('subnetPrefix')]",
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
              }
            }
          }
        ]
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[variables('nicName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('pipName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName')), '/subnets/', variables('subnetName'))]"
              }
            }
          }
        ],
        "networkSecurityGroup": {
          "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
        }
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[concat(variables('nicName'),'2')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('pipName'),'2')]",
        "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName')), '/subnets/', variables('subnetName'))]"
              }
            }
          }
        ],
        "networkSecurityGroup": {
          "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]"
        }
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('pipName')]",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard"
      },
      "apiVersion": "2017-08-01",
      "properties": {
        "publicIPAllocationMethod": "Static",
        "dnsSettings": {
          "domainNameLabel": "[variables('namingInfix')]"
        }
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[concat(variables('pipName'),'2')]",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard"
      },
      "apiVersion": "2017-08-01",
      "properties": {
        "publicIPAllocationMethod": "Static",
        "dnsSettings": {
          "domainNameLabel": "[concat(variables('namingInfix'),'2')]"
        }
      }
    },
    {
      "type": "Microsoft.Network/loadBalancers",
      "name": "[variables('lbName')]",
      "location": "[resourceGroup().location]",
      "apiVersion": "2017-08-01",
      "sku": {
        "name": "Standard"
      },
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('pipName'))]",
        "[concat('Microsoft.Network/publicIPAddresses/', variables('pipName'), '2')]"
      ],
      "tags": {
        "displayName": "Load Balancer"
      },
      "properties": {
        "frontendIPConfigurations": [
          {
            "name": "[variables('feIpConfigName')]",
            "properties": {
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('pipName'))]"
              }
            }
          },
          {
            "name": "[concat(variables('feIpConfigName'),'2')]",
            "properties": {
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('pipName'),'2'))]"
              }
            }
          }
        ],
        "backendAddressPools": [
          {
            "name": "[variables('bepoolName')]"
          },
          {
            "name": "[concat(variables('bepoolName'),'2')]"
          }
        ],
        "inboundNatPools": [
          {
            "name": "[variables('natPoolName')]",
            "properties": {
              "frontendIPConfiguration": {
                "id": "[variables('feIpConfigId')]"
              },
              "protocol": "tcp",
              "frontendPortRangeStart": 10022,
              "frontendPortRangeEnd": 11022,
              "backendPort": 22
            }
          },
          {
            "name": "[concat(variables('natPoolName'),'2')]",
            "properties": {
              "frontendIPConfiguration": {
                "id": "[concat(variables('feIpConfigId'),'2')]"
              },
              "protocol": "tcp",
              "frontendPortRangeStart": 20022,
              "frontendPortRangeEnd": 21022,
              "backendPort": 22
            }
          }
        ],
        "loadBalancingRules": [
          {
            "name": "HTTPRule",
            "properties": {
              "loadDistribution": "Default",
              "frontendIPConfiguration": {
                "id": "[variables('feIpConfigId')]"
              },
              "backendAddressPool": {
                "id": "[variables('bepoolID')]"
              },
              "protocol": "Tcp",
              "frontendPort": 80,
              "backendPort": 80,
              "enableFloatingIP": false,
              "idleTimeoutInMinutes": 5,
              "probe": {
                "id": "[concat(variables('lbId'), '/probes/', variables('httpProbeName'))]"
              }
            }
          },
          {
            "name": "HTTPSRule",
            "properties": {
              "loadDistribution": "Default",
              "frontendIPConfiguration": {
                "id": "[variables('feIpConfigId')]"
              },
              "backendAddressPool": {
                "id": "[variables('bepoolID')]"
              },
              "protocol": "Tcp",
              "frontendPort": 443,
              "backendPort": 443,
              "enableFloatingIP": false,
              "idleTimeoutInMinutes": 5,
              "probe": {
                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('lbName')), '/probes/', variables('httpsProbeName'))]"
              }
            }
          },
          {
            "name": "HTTPRule2",
            "properties": {
              "loadDistribution": "Default",
              "frontendIPConfiguration": {
                "id": "[concat(variables('feIpConfigId'),'2')]"
              },
              "backendAddressPool": {
                "id": "[concat(variables('bepoolID'),'2')]"
              },
              "protocol": "Tcp",
              "frontendPort": 80,
              "backendPort": 80,
              "enableFloatingIP": false,
              "idleTimeoutInMinutes": 5,
              "probe": {
                "id": "[concat(variables('lbId'), '/probes/', variables('httpProbeName'),'2')]"
              }
            }
          },
          {
            "name": "HTTPSRule2",
            "properties": {
              "loadDistribution": "Default",
              "frontendIPConfiguration": {
                "id": "[concat(variables('feIpConfigId'),'2')]"
              },
              "backendAddressPool": {
                "id": "[concat(variables('bepoolID'),'2')]"
              },
              "protocol": "Tcp",
              "frontendPort": 443,
              "backendPort": 443,
              "enableFloatingIP": false,
              "idleTimeoutInMinutes": 5,
              "probe": {
                "id": "[concat(resourceId('Microsoft.Network/loadBalancers', variables('lbName')), '/probes/', variables('httpsProbeName'),'2')]"
              }
            }
          }
        ],
        "probes": [
          {
            "name": "[variables('httpProbeName')]",
            "properties": {
              "protocol": "Http",
              "requestPath": "/artifactory/api/system/ping",
              "port": 80,
              "intervalInSeconds": 60,
              "numberOfProbes": 5
            }
          },
          {
            "name": "[variables('httpsProbeName')]",
            "properties": {
              "protocol": "Tcp",
              "port": 443,
              "intervalInSeconds": 60,
              "numberOfProbes": 5
            }
          },
          {
            "name": "[concat(variables('httpProbeName'),'2')]",
            "properties": {
              "protocol": "Http",
              "requestPath": "/artifactory/api/system/ping",
              "port": 80,
              "intervalInSeconds": 60,
              "numberOfProbes": 5
            }
          },
          {
            "name": "[concat(variables('httpsProbeName'),'2')]",
            "properties": {
              "protocol": "Tcp",
              "port": 443,
              "intervalInSeconds": 60,
              "numberOfProbes": 5
            }
          }
        ]
      }
    },
    {
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageAccountName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "accountType": "[variables('storageAccountType')]"
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "name": "deploySQLDB",
      "apiVersion": "2014-04-01",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('dbTemplateLocation')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "db_user": {
            "value": "[parameters('DB_Admin_User')]"
          },
          "db_password": {
            "value": "[parameters('DB_Admin_Password')]"
          },
          "db_server": {
            "value": "[variables('azureSqlServerName')]"
          },
          "db_name": {
            "value": "[parameters('DB_Name')]"
          },
          "db_edition": {
            "value": "[parameters('DB_Edition')]"
          },
          "db_location": {
            "value": "[parameters('DB_Location')]"
          }
        }
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachineScaleSets",
      "name": "[variables('scaleSetName')]",
      "location": "[resourceGroup().location]",
      "apiVersion": "2017-03-30",
      "dependsOn": [
        "[concat('Microsoft.Network/loadBalancers/', variables('lbName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
        "[concat('Microsoft.Resources/deployments/', 'deploySQLDB')]",
        "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]"
      ],
      "sku": {
        "name": "[parameters('vmSku')]",
        "tier": "Standard",
        "capacity": "[1]"
      },
      "properties": {
        "singlePlacementGroup": true,
        "upgradePolicy": {
          "mode": "Manual"
        },
        "virtualMachineProfile": {
          "storageProfile": {
            "osDisk": {
              "caching": "ReadWrite",
              "diskSizeGB": "250",
              "createOption": "FromImage"
            },
            "imageReference": "[variables('imageReference')]"
          },
          "osProfile": {
            "computerNamePrefix": "[variables('namingInfix')]",
            "adminUsername": "[parameters('adminUsername')]",
            "adminPassword": "[parameters('adminPassword')]",
            "customData": "[base64(concat('#INSTALL SCRIPT INPUTS\nCERTIFICATE_KEY=',parameters('certificateKey'),'\nCERTIFICATE=', parameters('certificate'),'\nCERTIFICATE_DOMAIN=',parameters('certificateDomain'),'\nARTIFACTORY_SERVER_NAME=',parameters('artifactoryServerName'),'\nEXTRA_JAVA_OPTS=',parameters('extraJavaOptions'),'\nJDBC_STR=',reference('Microsoft.Resources/deployments/deploySQLDB').outputs.jdbcConnString.value,'\nDB_NAME=',variables('DB_Name'),'\nDB_ADMIN_USER=',variables('DB_Admin_User'),'\nDB_ADMIN_PASSWD=',variables('DB_Admin_Password'),'\nSTO_ACT_NAME=',variables('storageAccountName'),'\nSTO_CTR_NAME=',variables('vmStorageAccountContainerName'),'\nSTO_ACT_KEY=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('apiVersion')).key1,'\nARTIFACTORY_VERSION=',variables('artifactoryVersion'),'\nMASTER_KEY=',variables('masterKey'),'\nIS_PRIMARY=','true','\nLICENSE1=',variables('artifactoryLicense1'),'\nLICENSE2=',variables('artifactoryLicense2'),'\nLICENSE3=',variables('artifactoryLicense3'),'\nLICENSE4=',variables('artifactoryLicense4'),'\nLICENSE5=',variables('artifactoryLicense5'),'\n'))]"
          },
          "networkProfile": {
            "networkInterfaceConfigurations": [
              {
                "name": "[variables('nicName')]",
                "properties": {
                  "primary": true,
                  "ipConfigurations": [
                    {
                      "name": "[concat(variables('ipConfigName'),'1')]",
                      "properties": {
                        "subnet": {
                          "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName')), '/subnets/', variables('subnetName'))]"
                        },
                        "loadBalancerBackendAddressPools": [
                          {
                            "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('lbName'), '/backendAddressPools/', variables('bePoolName'))]"
                          }
                        ],
                        "loadBalancerInboundNatPools": [
                          {
                            "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('lbName'), '/inboundNatPools/', variables('natPoolName'))]"
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          },
          "extensionProfile": {
            "extensions": [
              {
                "name": "extension1",
                "properties": {
                  "publisher": "Microsoft.Azure.Extensions",
                  "type": "CustomScript",
                  "typeHandlerVersion": "2.0",
                  "autoUpgradeMinorVersion": false,
                  "settings": {
                    "fileUris": [
                      "[concat(parameters('_artifactsLocation'), 'scripts/','install_artifactory.sh')]"
                    ]
                  },
                  "protectedSettings": {
                    "commandToExecute": "sh install_artifactory.sh"
                  }
                }
              }
            ]
          }
        }
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachineScaleSets",
      "name": "[concat(variables('scaleSetName'),'2')]",
      "location": "[resourceGroup().location]",
      "apiVersion": "2017-03-30",
      "dependsOn": [
        "[concat('Microsoft.Network/loadBalancers/', variables('lbName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
        "[concat('Microsoft.Compute/virtualMachineScaleSets/', variables('scaleSetName'))]",
        "[concat('Microsoft.Resources/deployments/', 'deploySQLDB')]",
        "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]"
      ],
      "sku": {
        "name": "[parameters('vmSku')]",
        "tier": "Standard",
        "capacity": "[parameters('nodeCount')]"
      },
      "properties": {
        "singlePlacementGroup": true,
        "upgradePolicy": {
          "mode": "Manual"
        },
        "virtualMachineProfile": {
          "storageProfile": {
            "osDisk": {
              "caching": "ReadWrite",
              "diskSizeGB": "250",
              "createOption": "FromImage"
            },
            "imageReference": "[variables('imageReference')]"
          },
          "osProfile": {
            "computerNamePrefix": "[variables('namingInfix')]",
            "adminUsername": "[parameters('adminUsername')]",
            "adminPassword": "[parameters('adminPassword')]",
            "customData": "[base64(concat('#INSTALL SCRIPT INPUTS\nCERTIFICATE_KEY=',parameters('certificateKey'),'\nCERTIFICATE=', parameters('certificate'),'\nCERTIFICATE_DOMAIN=',parameters('certificateDomain'),'\nARTIFACTORY_SERVER_NAME=',parameters('artifactoryServerName'),'\nEXTRA_JAVA_OPTS=',parameters('extraJavaOptions'),'\nJDBC_STR=',reference('Microsoft.Resources/deployments/deploySQLDB').outputs.jdbcConnString.value,'\nDB_NAME=',variables('DB_Name'),'\nDB_ADMIN_USER=',variables('DB_Admin_User'),'\nDB_ADMIN_PASSWD=',variables('DB_Admin_Password'),'\nSTO_ACT_NAME=',variables('storageAccountName'),'\nSTO_CTR_NAME=',variables('vmStorageAccountContainerName'),'\nSTO_ACT_KEY=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), variables('apiVersion')).key1,'\nARTIFACTORY_VERSION=',variables('artifactoryVersion'),'\nMASTER_KEY=',variables('masterKey'),'\nIS_PRIMARY=','false','\nLICENSE1=',variables('artifactoryLicense1'),'\nLICENSE2=',variables('artifactoryLicense2'),'\nLICENSE3=',variables('artifactoryLicense3'),'\nLICENSE4=',variables('artifactoryLicense4'),'\nLICENSE5=',variables('artifactoryLicense5'),'\n'))]"
          },
          "networkProfile": {
            "networkInterfaceConfigurations": [
              {
                "name": "[concat(variables('nicName'),'2')]",
                "properties": {
                  "primary": true,
                  "ipConfigurations": [
                    {
                      "name": "[concat(variables('ipConfigName'),'1')]",
                      "properties": {
                        "subnet": {
                          "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName')), '/subnets/', variables('subnetName'))]"
                        },
                        "loadBalancerBackendAddressPools": [
                          {
                            "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('lbName'), '/backendAddressPools/', variables('bePoolName'),'2')]"
                          }
                        ],
                        "loadBalancerInboundNatPools": [
                          {
                            "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('lbName'), '/inboundNatPools/', variables('natPoolName'),'2')]"
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          },
          "extensionProfile": {
            "extensions": [
              {
                "name": "extension1",
                "properties": {
                  "publisher": "Microsoft.Azure.Extensions",
                  "type": "CustomScript",
                  "typeHandlerVersion": "2.0",
                  "autoUpgradeMinorVersion": false,
                  "settings": {
                    "fileUris": [
                      "[concat(parameters('_artifactsLocation'), 'scripts/','install_artifactory.sh')]"
                    ]
                  },
                  "protectedSettings": {
                    "commandToExecute": "sh install_artifactory.sh"
                  }
                }
              }
            ]
          }
        }
      }
    }
  ],
  "outputs": {
    "fqdn": {
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',concat(variables('pipName'),'2')),'2016-03-30').dnsSettings.fqdn]",
      "type": "string"
    }
  }
}
