/deploy/terraform/terraform-units/modules/sap_system/app_tier/vm-webdisp.tf

https://github.com/Azure/sap-hana · Terraform · 249 lines · 206 code · 34 blank · 9 comment · 106 complexity · 17aba6f7966369e530f79b30ad58caec MD5 · raw file

  1. # Create Web dispatcher NICs
  2. resource "azurerm_network_interface" "web" {
  3. provider = azurerm.main
  4. count = local.enable_deployment ? local.webdispatcher_count : 0
  5. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.nic)
  6. location = var.resource_group[0].location
  7. resource_group_name = var.resource_group[0].name
  8. enable_accelerated_networking = local.web_sizing.compute.accelerated_networking
  9. ip_configuration {
  10. name = "IPConfig1"
  11. subnet_id = local.sub_web_deployed.id
  12. private_ip_address = local.use_DHCP ? (
  13. null) : (
  14. try(local.web_nic_ips[count.index], local.sub_web_defined ?
  15. cidrhost(local.sub_web_prefix, (tonumber(count.index) + local.ip_offsets.web_vm)) :
  16. cidrhost(local.sub_app_prefix, (tonumber(count.index) * -1 + local.ip_offsets.web_vm))
  17. )
  18. )
  19. private_ip_address_allocation = local.use_DHCP ? "Dynamic" : "Static"
  20. }
  21. }
  22. resource "azurerm_network_interface_application_security_group_association" "web" {
  23. count = local.enable_deployment ? local.webdispatcher_count : 0
  24. network_interface_id = azurerm_network_interface.web[count.index].id
  25. application_security_group_id = azurerm_application_security_group.web[0].id
  26. }
  27. # Create Application NICs
  28. resource "azurerm_network_interface" "web_admin" {
  29. provider = azurerm.main
  30. count = local.enable_deployment && local.apptier_dual_nics ? local.webdispatcher_count : 0
  31. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.admin_nic)
  32. location = var.resource_group[0].location
  33. resource_group_name = var.resource_group[0].name
  34. enable_accelerated_networking = local.app_sizing.compute.accelerated_networking
  35. ip_configuration {
  36. name = "IPConfig1"
  37. subnet_id = var.admin_subnet.id
  38. private_ip_address = local.use_DHCP ? (
  39. null) : (
  40. try(local.web_admin_nic_ips[count.index],
  41. cidrhost(var.admin_subnet.address_prefixes[0], tonumber(count.index) + local.admin_ip_offsets.web_vm
  42. )
  43. ))
  44. private_ip_address_allocation = local.use_DHCP ? "Dynamic" : "Static"
  45. }
  46. }
  47. # Create the Linux Web dispatcher VM(s)
  48. resource "azurerm_linux_virtual_machine" "web" {
  49. provider = azurerm.main
  50. depends_on = [var.anydb_vm_ids, var.hdb_vm_ids]
  51. count = local.enable_deployment ? (upper(local.web_ostype) == "LINUX" ? local.webdispatcher_count : 0) : 0
  52. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.vm)
  53. computer_name = local.web_computer_names[count.index]
  54. location = var.resource_group[0].location
  55. resource_group_name = var.resource_group[0].name
  56. proximity_placement_group_id = local.web_zonal_deployment ? var.ppg[count.index % max(local.web_zone_count, 1)].id : var.ppg[0].id
  57. //If more than one servers are deployed into a single zone put them in an availability set and not a zone
  58. availability_set_id = local.use_web_avset ? azurerm_availability_set.web[count.index % max(local.web_zone_count, 1)].id : null
  59. //If length of zones > 1 distribute servers evenly across zones
  60. zone = local.use_web_avset ? null : local.web_zones[count.index % max(local.web_zone_count, 1)]
  61. network_interface_ids = local.apptier_dual_nics ? (
  62. local.legacy_nic_order ? (
  63. [azurerm_network_interface.web_admin[count.index].id, azurerm_network_interface.web[count.index].id]) : (
  64. [azurerm_network_interface.web[count.index].id, azurerm_network_interface.web_admin[count.index].id]
  65. )
  66. ) : (
  67. [azurerm_network_interface.web[count.index].id]
  68. )
  69. size = length(local.web_size) > 0 ? local.web_size : local.web_sizing.compute.vm_size
  70. admin_username = var.sid_username
  71. admin_password = local.enable_auth_key ? null : var.sid_password
  72. disable_password_authentication = !local.enable_auth_password
  73. dynamic "admin_ssh_key" {
  74. for_each = range(var.deployment == "new" ? 1 : (local.enable_auth_password ? 0 : 1))
  75. content {
  76. username = var.sid_username
  77. public_key = var.sdu_public_key
  78. }
  79. }
  80. dynamic "os_disk" {
  81. iterator = disk
  82. for_each = flatten(
  83. [
  84. for storage_type in local.web_sizing.storage : [
  85. for disk_count in range(storage_type.count) :
  86. {
  87. name = storage_type.name,
  88. id = disk_count,
  89. disk_type = storage_type.disk_type,
  90. size_gb = storage_type.size_gb,
  91. caching = storage_type.caching
  92. }
  93. ]
  94. if storage_type.name == "os"
  95. ]
  96. )
  97. content {
  98. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.osdisk)
  99. caching = disk.value.caching
  100. storage_account_type = disk.value.disk_type
  101. disk_size_gb = disk.value.size_gb
  102. disk_encryption_set_id = try(var.options.disk_encryption_set_id, null)
  103. }
  104. }
  105. source_image_id = local.web_custom_image ? local.web_os.source_image_id : null
  106. dynamic "source_image_reference" {
  107. for_each = range(local.web_custom_image ? 0 : 1)
  108. content {
  109. publisher = local.web_os.publisher
  110. offer = local.web_os.offer
  111. sku = local.web_os.sku
  112. version = local.web_os.version
  113. }
  114. }
  115. boot_diagnostics {
  116. storage_account_uri = var.storage_bootdiag_endpoint
  117. }
  118. tags = local.web_tags
  119. }
  120. # Create the Windows Web dispatcher VM(s)
  121. resource "azurerm_windows_virtual_machine" "web" {
  122. provider = azurerm.main
  123. depends_on = [var.anydb_vm_ids, var.hdb_vm_ids]
  124. count = local.enable_deployment ? (upper(local.web_ostype) == "WINDOWS" ? local.webdispatcher_count : 0) : 0
  125. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.vm)
  126. computer_name = local.web_computer_names[count.index]
  127. location = var.resource_group[0].location
  128. resource_group_name = var.resource_group[0].name
  129. proximity_placement_group_id = local.web_zonal_deployment ? var.ppg[count.index % max(local.web_zone_count, 1)].id : var.ppg[0].id
  130. //If more than one servers are deployed into a single zone put them in an availability set and not a zone
  131. availability_set_id = local.use_web_avset ? azurerm_availability_set.web[count.index % max(local.web_zone_count, 1)].id : null
  132. //If length of zones > 1 distribute servers evenly across zones
  133. zone = local.use_web_avset ? null : local.web_zones[count.index % max(local.web_zone_count, 1)]
  134. network_interface_ids = local.apptier_dual_nics ? (
  135. local.legacy_nic_order ? (
  136. [azurerm_network_interface.web_admin[count.index].id, azurerm_network_interface.web[count.index].id]) : (
  137. [azurerm_network_interface.web[count.index].id, azurerm_network_interface.web_admin[count.index].id]
  138. )
  139. ) : (
  140. [azurerm_network_interface.web[count.index].id]
  141. )
  142. size = local.web_sizing.compute.vm_size
  143. admin_username = var.sid_username
  144. admin_password = var.sid_password
  145. dynamic "os_disk" {
  146. iterator = disk
  147. for_each = flatten(
  148. [
  149. for storage_type in local.web_sizing.storage : [
  150. for disk_count in range(storage_type.count) :
  151. {
  152. name = storage_type.name,
  153. id = disk_count,
  154. disk_type = storage_type.disk_type,
  155. size_gb = storage_type.size_gb,
  156. caching = storage_type.caching
  157. }
  158. ]
  159. if storage_type.name == "os"
  160. ]
  161. )
  162. content {
  163. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[count.index], local.resource_suffixes.osdisk)
  164. caching = disk.value.caching
  165. storage_account_type = disk.value.disk_type
  166. disk_size_gb = disk.value.size_gb
  167. disk_encryption_set_id = try(var.options.disk_encryption_set_id, null)
  168. }
  169. }
  170. source_image_id = local.web_custom_image ? local.web_os.source_image_id : null
  171. dynamic "source_image_reference" {
  172. for_each = range(local.web_custom_image ? 0 : 1)
  173. content {
  174. publisher = local.web_os.publisher
  175. offer = local.web_os.offer
  176. sku = local.web_os.sku
  177. version = local.web_os.version
  178. }
  179. }
  180. boot_diagnostics {
  181. storage_account_uri = var.storage_bootdiag_endpoint
  182. }
  183. tags = local.web_tags
  184. }
  185. # Creates managed data disk
  186. resource "azurerm_managed_disk" "web" {
  187. provider = azurerm.main
  188. count = local.enable_deployment ? length(local.web_data_disks) : 0
  189. name = format("%s%s%s%s", local.prefix, var.naming.separator, local.web_virtualmachine_names[local.web_data_disks[count.index].vm_index], local.web_data_disks[count.index].suffix)
  190. location = var.resource_group[0].location
  191. resource_group_name = var.resource_group[0].name
  192. create_option = "Empty"
  193. storage_account_type = local.web_data_disks[count.index].storage_account_type
  194. disk_size_gb = local.web_data_disks[count.index].disk_size_gb
  195. disk_encryption_set_id = try(var.options.disk_encryption_set_id, null)
  196. zones = local.web_zonal_deployment && (local.webdispatcher_count == local.web_zone_count) ? (
  197. upper(local.web_ostype) == "LINUX" ? (
  198. [azurerm_linux_virtual_machine.web[local.web_data_disks[count.index].vm_index].zone]) : (
  199. [azurerm_windows_virtual_machine.web[local.web_data_disks[count.index].vm_index].zone]
  200. )) : (
  201. null
  202. )
  203. }
  204. resource "azurerm_virtual_machine_data_disk_attachment" "web" {
  205. provider = azurerm.main
  206. count = local.enable_deployment ? length(local.web_data_disks) : 0
  207. managed_disk_id = azurerm_managed_disk.web[count.index].id
  208. virtual_machine_id = upper(local.web_ostype) == "LINUX" ? (
  209. azurerm_linux_virtual_machine.web[local.web_data_disks[count.index].vm_index].id) : (
  210. azurerm_windows_virtual_machine.web[local.web_data_disks[count.index].vm_index].id
  211. )
  212. caching = local.web_data_disks[count.index].caching
  213. write_accelerator_enabled = local.web_data_disks[count.index].write_accelerator_enabled
  214. lun = local.web_data_disks[count.index].lun
  215. }