0
votes

I am using ARM template to deploy ELK stack onto azure cloud (in an existing vnet,subnet,security group) but if I use the default template from https://github.com/elastic/azure-marketplace it deploys a network security group as well for kibana. How can I edit the template so as to use only the network security group thats already existing and not create a new one.

1
Let me know it my answer works for youjuvchan
dint work :( .. also I know that we have to purchase this template if I do it from azure portal via azure marketplace offering but do I still have to purchase it if Im using the arm templates method to deploy?Negi Anurag
What error do you get?juvchan
Did not get any error but the network security group hostname-kibana-nsg gets created anyhow.Negi Anurag
If I deploy it via ARM templates, is it free?Negi Anurag

1 Answers

0
votes

To reuse existing network security group resource, you could modify the src/machines/kibana-resources.json as below:

  1. Remove the network security group resource
  2. Create a new parameter for network security group (securityGroupName) with default value This way you can pass in the value of the existing network security group name

  3. Remove the network security group variable

Here is the modified template which should meet your requirement.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "templateBaseUrl": {
      "type": "string",
      "metadata": {
        "description": "Base uri of resources"
      }
    },
    "location": {
      "type": "string",
      "metadata": {
        "description": "Location where resources will be provisioned"
      }
    },
    "namespace": {
      "type": "string",
      "metadata": {
        "description": "The unique namespace for the Kibana VM"
      }
    },
    "securityGroupName": {
      "type": "string",
      "defaultValue": "[concat(parameters('namespace'), '-nsg')]"
    },
    "networkSettings": {
      "type": "object",
      "metadata": {
        "description": "Network settings"
      }
    },
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "Existing Storage Account where the Virtual Machine's disks will be placed"
      }
    },
    "credentials": {
      "type": "secureObject",
      "metadata": {
        "description": "Credentials information block"
      }
    },
    "osSettings": {
      "type": "object",
      "metadata": {
        "description": "Platform and OS settings"
      }
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_A1",
      "metadata": {
        "description": "Size of the Kibana VM"
      }
    }
  },
  "variables": {
    "namespace": "[parameters('namespace')]",
    "subnetId": "[concat(resourceId(parameters('networkSettings').resourceGroup, 'Microsoft.Network/virtualNetworks', parameters('networkSettings').name), '/subnets/', parameters('networkSettings').subnet.name)]",
    "publicIpName": "[concat(variables('namespace'), '-ip')]",
    "nicName": "[concat(variables('namespace'), '-nic')]",
    "password_osProfile": {
      "computername": "[parameters('namespace')]",
      "adminUsername": "[parameters('credentials').adminUsername]",
      "adminPassword": "[parameters('credentials').password]"
    },
    "sshPublicKey_osProfile": {
      "computername": "[parameters('namespace')]",
      "adminUsername": "[parameters('credentials').adminUsername]",
      "linuxConfiguration": {
        "disablePasswordAuthentication": "true",
        "ssh": {
          "publicKeys": [
            {
              "path": "[concat('/home/', parameters('credentials').adminUsername, '/.ssh/authorized_keys')]",
              "keyData": "[parameters('credentials').sshPublicKey]"
            }
          ]
        }
      }
    },
    "osProfile": "[variables(concat(parameters('credentials').authenticationType, '_osProfile'))]"
  },
  "resources": [
    {
      "apiVersion": "2016-03-30",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('publicIpName')]",
      "location": "[parameters('location')]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic",
        "dnsSettings": {
          "domainNameLabel": "[concat('kb-', uniqueString(resourceGroup().id))]"
        }
      }
    },
    {
      "apiVersion": "2016-03-30",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[variables('nicName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIpName'))]",
        "[concat('Microsoft.Network/networkSecurityGroups/', parameters('securityGroupName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIpName'))]"
              },
              "subnet": {
                "id": "[variables('subnetId')]"
              }
            }
          }
        ],
        "networkSecurityGroup": {
          "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('securityGroupName'))]"
        }
      }
    },
    {
      "apiVersion": "2016-03-30",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('namespace')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": "[variables('osProfile')]",
        "storageProfile": {
          "imageReference": "[parameters('osSettings').imageReference]",
          "osDisk": {
            "name": "osdisk",
            "vhd": {
              "uri": "[concat('http://', parameters('storageAccountName'),'.blob.core.windows.net/vhds/', parameters('namespace'), '-osdisk.vhd')]"
            },
            "caching": "ReadWrite",
            "createOption": "FromImage"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        }
      },
      "resources": [
        {
          "type": "Microsoft.Compute/virtualMachines/extensions",
          "name": "[concat(variables('namespace'), '/script')]",
          "apiVersion": "2016-03-30",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[concat('Microsoft.Compute/virtualMachines/', parameters('namespace'))]"
          ],
          "properties": "[parameters('osSettings').extensionSettings.kibana]"
        }
      ]
    }
  ],
  "outputs": {
    "fqdn": {
      "value": "[concat('http://',reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpName')),providers('Microsoft.Network', 'publicIPAddresses').apiVersions[0]).dnsSettings.fqdn, ':5601')]",
      "type": "string"
    }
  }
}