main.tf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # cybergav.in - 3rd July 2021
  2. # USE-CASE: Test network latency between endpoints in the same VNet. The VM SKU and settings will have a bearing on network performance.
  3. #
  4. #########################################################################################################################################
  5. #
  6. # Terraform Provider Configuration
  7. #
  8. terraform {
  9. required_version = ">= 0.15"
  10. required_providers {
  11. azurerm = {
  12. source = "hashicorp/azurerm"
  13. version = "=2.58.0"
  14. }
  15. }
  16. }
  17. provider "azurerm" {
  18. features {}
  19. }
  20. #
  21. # Locals
  22. #
  23. locals {
  24. custom_data = <<CUSTOM_DATA
  25. #!/bin/bash
  26. sudo dnf -y install qperf
  27. sudo systemctl stop firewalld
  28. sudo systemctl disable firewalld
  29. CUSTOM_DATA
  30. }
  31. #
  32. # Resource Group
  33. #
  34. resource "azurerm_resource_group" "rg" {
  35. name = "${var.prefix}-rg"
  36. location = var.location
  37. }
  38. #
  39. # Virtual Networks and Subnets
  40. #
  41. resource "azurerm_virtual_network" "vnet" {
  42. name = "${var.prefix}-vnet"
  43. address_space = ["10.100.0.0/16"]
  44. location = var.location
  45. resource_group_name = azurerm_resource_group.rg.name
  46. subnet {
  47. name = "${var.prefix}-snet1"
  48. address_prefix = "10.100.1.0/24"
  49. }
  50. subnet {
  51. name = "${var.prefix}-snet2"
  52. address_prefix = "10.100.2.0/24"
  53. }
  54. }
  55. #
  56. # Public IPs
  57. #
  58. resource "azurerm_public_ip" "pip1" {
  59. name = "${var.prefix}-pip1"
  60. resource_group_name = azurerm_resource_group.rg.name
  61. location = var.location
  62. allocation_method = "Dynamic"
  63. }
  64. resource "azurerm_public_ip" "pip2" {
  65. name = "${var.prefix}-pip2"
  66. resource_group_name = azurerm_resource_group.rg.name
  67. location = var.location
  68. allocation_method = "Dynamic"
  69. }
  70. #
  71. # Virtual Machine NICs
  72. #
  73. resource "azurerm_network_interface" "vm1_nic" {
  74. name = "${var.prefix}-vm1-nic"
  75. location = var.location
  76. resource_group_name = azurerm_resource_group.rg.name
  77. ip_configuration {
  78. name = "internal"
  79. subnet_id = azurerm_virtual_network.vnet.subnet.*.id[0]
  80. private_ip_address_allocation = "Dynamic"
  81. public_ip_address_id = azurerm_public_ip.pip1.id
  82. }
  83. }
  84. resource "azurerm_network_interface" "vm2_nic" {
  85. name = "${var.prefix}-vm2-nic"
  86. location = var.location
  87. resource_group_name = azurerm_resource_group.rg.name
  88. ip_configuration {
  89. name = "internal"
  90. subnet_id = azurerm_virtual_network.vnet.subnet.*.id[1]
  91. private_ip_address_allocation = "Dynamic"
  92. public_ip_address_id = azurerm_public_ip.pip2.id
  93. }
  94. }
  95. #
  96. # Virtual Machines
  97. #
  98. resource "azurerm_linux_virtual_machine" "vm1" {
  99. name = "${var.prefix}-vm1"
  100. resource_group_name = azurerm_resource_group.rg.name
  101. location = var.location
  102. size = "Standard_B1s"
  103. admin_username = var.admin_username
  104. admin_password = var.admin_password
  105. disable_password_authentication = false
  106. custom_data = base64encode(local.custom_data)
  107. network_interface_ids = [
  108. azurerm_network_interface.vm1_nic.id,
  109. ]
  110. os_disk {
  111. caching = "ReadWrite"
  112. storage_account_type = "Standard_LRS"
  113. }
  114. source_image_reference {
  115. publisher = "oracle"
  116. offer = "oracle-linux"
  117. sku = "ol84-lvm-gen2"
  118. version = "latest"
  119. }
  120. }
  121. resource "azurerm_linux_virtual_machine" "vm2" {
  122. name = "${var.prefix}-vm2"
  123. resource_group_name = azurerm_resource_group.rg.name
  124. location = var.location
  125. size = "Standard_B1s"
  126. admin_username = var.admin_username
  127. admin_password = var.admin_password
  128. disable_password_authentication = false
  129. custom_data = base64encode(local.custom_data)
  130. network_interface_ids = [
  131. azurerm_network_interface.vm2_nic.id,
  132. ]
  133. os_disk {
  134. caching = "ReadWrite"
  135. storage_account_type = "Standard_LRS"
  136. }
  137. source_image_reference {
  138. publisher = "oracle"
  139. offer = "oracle-linux"
  140. sku = "ol84-lvm-gen2"
  141. version = "latest"
  142. }
  143. }