When you create a Service Fabric cluster using the Azure Portal, there is no way to select an existing Virtual Network (VNET) to host the cluster in. Usually there is no harm in running the cluster in its own VNET. However, when you’ve got an existing VNET to support integration with a third party using a VPN tunnel, this may become a problem. Reconfiguring / recreating the VPN tunnel whenever a new cluster is deployed is not an ideal situation.

Fortunately, it’s relatively easy to make some changes to the ARM template used by the Azure Portal to support an existing VNET.

First, you need to get the ARM template. When creating a Service Fabric cluster in the Azure Portal, you can choose to download the generated template in the last step of the wizard:

DownloadTemplate.png

Now all you need to do is remove some stuff from the template we don’t need.

First, delete the resource for the VNET. You can find the relevant resource by looking at its resource type, which should be Microsoft.Network/virtualNetworks. It should look something like this:

{
  "apiVersion": "[variables('vNetApiVersion')]",
  "type": "Microsoft.Network/virtualNetworks",
  "name": "[parameters('virtualNetworkName')]",
  "location": "[parameters('computeLocation')]",
  "properties": {
    "addressSpace": {
      "addressPrefixes": [
        "[parameters('addressPrefix')]"
      ]
    },
    "subnets": [
      {
        "name": "[parameters('subnet0Name')]",
        "properties": {
          "addressPrefix": "[parameters('subnet0Prefix')]"
        }
      }
    ]
  },
  "tags": {
    "resourceType": "Service Fabric",
    "clusterName": "[parameters('clusterName')]"
  }
},

You can remove that entire resource from the template.

Next, you should remove any parameters that were only used by the VNET resource. Both subnet0Prefix and addressPrefix can be safely removed.

Now you can run the template to deploy the cluster in an existing VNET by configuring the following parameters:

  • virtualNetworkName: Name of the VNET you want to use.
  • subnet0Name: Name of an existing VNET subnet where you want to provision the cluster in.