devopscloudguru

Untitled

Feb 3rd, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.99 KB | None | 0 0
  1. # Declaring variables for terraform configuration
  2.  
  3. variable "ARM_SUBSCRIPTION_ID" {}
  4.  
  5. variable "ARM_CLIENT_ID" {}
  6.  
  7. variable "ARM_CLIENT_SECRET" {}
  8.  
  9. variable "ARM_TENANT_ID" {}
  10.  
  11. # Declare env variable
  12. variable "env" {}
  13.  
  14. # Declare storage account details
  15. variable "sto_acc_tier_std" {}
  16. variable "sto_acc_rep_type_lrs" {}
  17.  
  18. # Declare Host basename
  19. variable "ax_base_hostname" {}
  20.  
  21. # Declare VM details
  22. variable "image_publisher" {}
  23.  
  24. variable "image_offer_win" {}
  25.  
  26. variable "sku_2016_datacentre" {}
  27.  
  28. variable "image_version" {}
  29.  
  30. # End of declaring variables
  31.  
  32. # Declaring various resources
  33. ###################################################################################################
  34. # Standard for Declaring Terraform Internal Variables
  35. ###################################################################################################
  36. # tf-{abbreviated resource type}-{Environment Name}
  37. # rg - Resource Group
  38. # vn - Virtual Network
  39. # sn - Subnet
  40. # ni - Network Interface
  41. # sa - Storage Account
  42. # vm - Virtual Machine
  43. # mdsk - Managed Disk
  44. # as - Availability Set
  45.  
  46. ###################################################################################################
  47. #
  48. ###################################################################################################
  49.  
  50. # Resource Group
  51. resource "azurerm_resource_group" "tf-rg-cluster-internal" {
  52. name = "rg_app"
  53. location = "southeastasia"
  54.  
  55. tags {
  56. environment = "${var.env}"
  57. }
  58. }
  59.  
  60. # Reference existing resource group for Virtual Network
  61. data "azurerm_resource_group" "tf-rg-cluster-external" {
  62. name = "rg_vnets"
  63. }
  64.  
  65. # Reference existing Virtual Network
  66. data "azurerm_virtual_network" "tf-vn-cluster" {
  67. name = "vnet_frednxt_groups_preprod"
  68. resource_group_name = "${data.azurerm_resource_group.tf-rg-cluster-external.name}"
  69. }
  70.  
  71. # Reference existing subnet
  72.  
  73. # # Virtual Network
  74. # resource "azurerm_virtual_network" "tf-vn-cluster" {
  75. # name = "cluster-vn"
  76. # address_space = ["10.0.0.0/16"]
  77. # location = "${azurerm_resource_group.tf-rg-cluster.location}"
  78. # resource_group_name = "${azurerm_resource_group.tf-rg-cluster.name}"
  79. # }
  80.  
  81. # Subnet
  82.  
  83. data "azurerm_subnet" "tf-sn-cluster" {
  84. name = "subnet_app"
  85. virtual_network_name = "${data.azurerm_virtual_network.tf-vn-cluster.name}"
  86. resource_group_name = "${data.azurerm_resource_group.tf-rg-cluster-external.name}"
  87. }
  88.  
  89. # resource "azurerm_subnet" "tf-sn-cluster" {
  90. # name = "cluster-sn"
  91. # resource_group_name = "${azurerm_resource_group.tf-rg-cluster.name}"
  92. # virtual_network_name = "${azurerm_virtual_network.tf-vn-cluster.name}"
  93. # address_prefix = "10.0.2.0/24"
  94. # }
  95.  
  96. # Network Interface
  97. resource "azurerm_network_interface" "tf-ni-cluster" {
  98. count = 5
  99. name = "${var.ax_base_hostname}-NI-${count.index}"
  100. location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
  101. resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
  102.  
  103. ip_configuration {
  104. name = "${var.ax_base_hostname}_${count.index}.IP"
  105. subnet_id = "${data.azurerm_subnet.tf-sn-cluster.id}"
  106. private_ip_address_allocation = "static"
  107. private_ip_address ="10.100.1.${count.index+5}"
  108. }
  109. tags {
  110. environment = "${var.env}"
  111. }
  112. }
  113.  
  114. # Storage Account
  115. resource "azurerm_storage_account" "tf-sa-cluster" {
  116. name = "${lower(var.ax_base_hostname)}stoacc${count.index}"
  117. location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
  118. resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
  119. account_tier = "${var.sto_acc_tier_std}"
  120. account_replication_type = "${var.sto_acc_rep_type_lrs}"
  121.  
  122. tags {
  123. environment = "${var.env}"
  124. }
  125. }
  126.  
  127. # Optional Managed Data Disk
  128. resource "azurerm_managed_disk" "tf-mdsk-cluster" {
  129. count = 5
  130. name = "${var.ax_base_hostname}-DATADISK-${count.index}"
  131. location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
  132. resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
  133. storage_account_type = "Standard_LRS"
  134. create_option = "Empty"
  135. disk_size_gb = "1024"
  136. }
  137.  
  138.  
  139. # Availability Set
  140. resource "azurerm_availability_set" "tf-as-cluster" {
  141. name = "avset"
  142. location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
  143. resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
  144. platform_fault_domain_count = 2
  145. platform_update_domain_count = 2
  146. managed = true
  147.  
  148. tags {
  149. environment = "${var.env}"
  150. }
  151. }
  152.  
  153. resource "azurerm_virtual_machine" "tf-vm-cluster" {
  154. count = 5
  155. name = "${var.ax_base_hostname}-${count.index}"
  156. location = "${azurerm_resource_group.tf-rg-cluster-internal.location}"
  157. availability_set_id = "${azurerm_availability_set.tf-as-cluster.id}"
  158. resource_group_name = "${azurerm_resource_group.tf-rg-cluster-internal.name}"
  159. network_interface_ids = ["${element(azurerm_network_interface.tf-ni-cluster.*.id, count.index)}"]
  160. vm_size = "Standard_DS1_v2"
  161.  
  162. # Uncomment this line to delete the OS disk automatically when deleting the VM
  163. delete_os_disk_on_termination = true
  164.  
  165. # Uncomment this line to delete the data disks automatically when deleting the VM
  166. delete_data_disks_on_termination = true
  167.  
  168. storage_image_reference {
  169. publisher = "${var.image_publisher}"
  170. offer = "${var.image_offer_win}"
  171. sku = "${var.sku_2016_datacentre}"
  172. version = "${var.image_version}"
  173. }
  174.  
  175. storage_os_disk {
  176. name = "${var.ax_base_hostname}-OS-DISK-${count.index}"
  177. caching = "ReadWrite"
  178. create_option = "FromImage"
  179. managed_disk_type = "Standard_LRS"
  180. }
  181.  
  182. # Optional data disks
  183. storage_data_disk {
  184. name = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.name, count.index)}"
  185. managed_disk_id = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.id, count.index)}"
  186. create_option = "Attach"
  187. lun = 0
  188. disk_size_gb = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.disk_size_gb, count.index)}"
  189. }
  190.  
  191. storage_data_disk {
  192. name = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.name, count.index+1)}"
  193. managed_disk_id = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.id, count.index)}"
  194. create_option = "Attach"
  195. lun = 1
  196. disk_size_gb = "${element(azurerm_managed_disk.tf-mdsk-cluster.*.disk_size_gb, count.index)}"
  197. }
  198.  
  199. os_profile {
  200. computer_name = "${var.ax_base_hostname}-${count.index}"
  201. admin_username = "scmadmin"
  202. admin_password = "HashDollar135"
  203. }
  204.  
  205. os_profile_windows_config {
  206. enable_automatic_upgrades = false
  207. }
  208.  
  209. tags {
  210. environment = "${var.env}"
  211. }
  212. }
Add Comment
Please, Sign In to add comment