Browse Source

first commit

cybergavin 4 years ago
parent
commit
bdf14b9afc

+ 47 - 0
az-tfl-vnetpeer-perf/README.md

@@ -0,0 +1,47 @@
+# Azure Terraform Lab - az-tfl-vnetpeer-perf - Network Performance between VMs in different VNets, across VNet peerings
+
+## Topology
+
+![az-tfl-vnetpeer-perf-topology](az-tfl-vnetpeer-perf-topology.png)
+
+
+## Resources created
+
+This Lab creates the following Azure resources (prefix 'cg' used for names):
+
+![az-tfl-vnetpeer-perf-resources](az-tfl-vnetpeer-perf-resources.png)
+
+
+## Use-Cases
+
+- Measure network performance (e.g. throughput, latency) between VMs (Oracle Linux) in **different** VNets across VNet peerings
+- qperf is installed  and firewalld is disabled on both VMs 
+- You may use ping, iperf3 or other network performance tools (may have to be installed)
+
+
+## Usage
+
+- Authenticate with Azure (e.g. Azure CLI) and switch to the appropriate subscription (az account set -s <subscription>)
+- Configure appropriate values for the variables in terraform.tfvars
+- ```terraform init```
+- ```terraform apply```
+- Evaluate/Test/Demo
+- ```terraform destroy```
+
+
+
+## Example - qperf
+
+- On vm1, use qperf to listen
+
+```sudo qperf```
+
+- On vm2, use qperf to connect to vm1 (private IP) and test TCP bandwidth and latency for 10 seconds 
+
+```sudo qperf <vm1 private IP> -t 10 tcp_bw tcp_lat```
+
+
+## References
+
+- [qperf](https://linux.die.net/man/1/qperf)
+- [iperf3](https://iperf.fr/iperf-doc.php)

BIN
az-tfl-vnetpeer-perf/az-tfl-vnetpeer-perf-resources.png


BIN
az-tfl-vnetpeer-perf/az-tfl-vnetpeer-perf-topology.png


+ 170 - 0
az-tfl-vnetpeer-perf/main.tf

@@ -0,0 +1,170 @@
+# cybergav.in - 4th July 2021
+# USE-CASE: Test network latency between endpoints in different VNet across VNet peering connections. The VM SKU and settings will have a bearing on network performance.
+#
+#########################################################################################################################################
+#
+# Terraform Provider Configuration
+#
+terraform {
+  required_version = ">= 0.15"
+  required_providers {
+    azurerm = {
+      source  = "hashicorp/azurerm"
+      version = "=2.58.0"
+    }
+  }
+}
+provider "azurerm" {
+  features {}
+}
+#
+# Locals
+#
+locals {
+custom_data = <<CUSTOM_DATA
+#!/bin/bash
+sudo dnf -y install qperf
+sudo systemctl stop firewalld 
+sudo systemctl disable firewalld 
+CUSTOM_DATA
+}
+#
+# Resource Group 
+#
+resource "azurerm_resource_group" "rg" {
+  name     = "${var.prefix}-rg"
+  location = var.location
+}
+#
+# Virtual Networks and Subnets
+#
+resource "azurerm_virtual_network" "vnet1" {
+  name                = "${var.prefix}-vnet-1"
+  address_space       = ["10.100.0.0/16"]
+  location            = var.location
+  resource_group_name = azurerm_resource_group.rg.name
+  subnet {
+    name           = "${var.prefix}-snet-1"
+    address_prefix = "10.100.0.0/24"
+  }
+}
+resource "azurerm_virtual_network" "vnet2" {
+  name                = "${var.prefix}-vnet-2"
+  address_space       = ["10.200.0.0/16"]
+  location            = var.location
+  resource_group_name = azurerm_resource_group.rg.name
+  subnet {
+    name           = "${var.prefix}-snet-2"
+    address_prefix = "10.200.0.0/24"
+  }
+}
+#
+# Virtual Network Peerings
+#
+resource "azurerm_virtual_network_peering" "peer1" {
+  name                      = "cg-peering-vnet1-to-vnet2"
+  resource_group_name       = azurerm_resource_group.rg.name
+  virtual_network_name      = azurerm_virtual_network.vnet1.name
+  remote_virtual_network_id = azurerm_virtual_network.vnet2.id
+}
+resource "azurerm_virtual_network_peering" "peer2" {
+  name                      = "cg-peering-vnet2-to-vnet1"
+  resource_group_name       = azurerm_resource_group.rg.name
+  virtual_network_name      = azurerm_virtual_network.vnet2.name
+  remote_virtual_network_id = azurerm_virtual_network.vnet1.id
+}
+#
+# Public IPs
+#
+resource "azurerm_public_ip" "pip1" {
+  name                = "${var.prefix}-pip1"
+  resource_group_name = azurerm_resource_group.rg.name
+  location            = var.location
+  allocation_method   = "Dynamic"
+}
+resource "azurerm_public_ip" "pip2" {
+  name                = "${var.prefix}-pip2"
+  resource_group_name = azurerm_resource_group.rg.name
+  location            = var.location
+  allocation_method   = "Dynamic"
+}
+#
+# Virtual Machine NICs
+#
+resource "azurerm_network_interface" "vm1_nic" {
+  name                = "${var.prefix}-vm1-nic"
+  location            = var.location
+  resource_group_name = azurerm_resource_group.rg.name
+
+  ip_configuration {
+    name                          = "internal"
+    subnet_id                     = azurerm_virtual_network.vnet1.subnet.*.id[0]
+    private_ip_address_allocation = "Dynamic"
+    public_ip_address_id          = azurerm_public_ip.pip1.id
+  }
+}
+resource "azurerm_network_interface" "vm2_nic" {
+  name                = "${var.prefix}-vm2-nic"
+  location            = var.location
+  resource_group_name = azurerm_resource_group.rg.name
+
+  ip_configuration {
+    name                          = "internal"
+    subnet_id                     = azurerm_virtual_network.vnet2.subnet.*.id[0]
+    private_ip_address_allocation = "Dynamic"
+    public_ip_address_id          = azurerm_public_ip.pip2.id
+  }
+}
+#
+# Virtual Machines
+#
+resource "azurerm_linux_virtual_machine" "vm1" {
+  name                            = "${var.prefix}-vm1"
+  resource_group_name             = azurerm_resource_group.rg.name
+  location                        = var.location
+  size                            = "Standard_B1s"
+  admin_username                  = var.admin_username
+  admin_password                  = var.admin_password
+  disable_password_authentication = false
+  custom_data                     = base64encode(local.custom_data)
+  network_interface_ids = [
+    azurerm_network_interface.vm1_nic.id,
+  ]
+
+  os_disk {
+    caching              = "ReadWrite"
+    storage_account_type = "Standard_LRS"
+  }
+
+  source_image_reference {
+    publisher = "oracle"
+    offer     = "oracle-linux"
+    sku       = "ol84-lvm-gen2"
+    version   = "latest"
+  }
+}
+resource "azurerm_linux_virtual_machine" "vm2" {
+  name                            = "${var.prefix}-vm2"
+  resource_group_name             = azurerm_resource_group.rg.name
+  location                        = var.location
+  size                            = "Standard_B1s"
+  admin_username                  = var.admin_username
+  admin_password                  = var.admin_password
+  disable_password_authentication = false
+  custom_data                     = base64encode(local.custom_data)
+  network_interface_ids = [
+    azurerm_network_interface.vm2_nic.id,
+  ]
+
+  os_disk {
+    caching              = "ReadWrite"
+    storage_account_type = "Standard_LRS"
+  }
+
+  source_image_reference {
+    publisher = "oracle"
+    offer     = "oracle-linux"
+    sku       = "ol84-lvm-gen2"
+    version   = "latest"
+  }
+}

+ 4 - 0
az-tfl-vnetpeer-perf/terraform.tfvars

@@ -0,0 +1,4 @@
+prefix         = ""
+location       = ""
+admin_username = ""
+admin_password = ""

+ 17 - 0
az-tfl-vnetpeer-perf/variables.tf

@@ -0,0 +1,17 @@
+variable "prefix" {
+  type        = string
+  description = "(Required) Prefix to be used in names of all resources"
+}
+variable "location" {
+  type        = string
+  description = "(Required) Location of all resources and resource group"
+}
+variable "admin_username" {
+  type        = string
+  description = "(Required) Username for the admin user for SSH access"
+}
+variable "admin_password" {
+  type        = string
+  description = "(Required) Password for the admin user for SSH access"
+  sensitive   = true
+}