Guest User

Untitled

a guest
May 30th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. # resource group definitions
  2. resource "azurerm_resource_group" "rg" {
  3. name = "${var.resource_group}"
  4. location = "${var.location}"
  5. }
  6.  
  7. resource "azurerm_storage_account" "stor" {
  8. name = "${var.rg_prefix}stor${count.index}"
  9. location = "${var.location}"
  10. resource_group_name = "${azurerm_resource_group.rg.name}"
  11. account_tier = "${var.storage_account_tier}"
  12. account_replication_type = "${var.storage_replication_type}"
  13. }
  14.  
  15. resource "azurerm_public_ip" "pip" {
  16. name = "${var.rg_prefix}-ip${count.index}"
  17. location = "${var.location}"
  18. resource_group_name = "${azurerm_resource_group.rg.name}"
  19. public_ip_address_allocation = "dynamic"
  20. }
  21.  
  22. # network definitions
  23. resource "azurerm_virtual_network" "vnet" {
  24. name = "${var.virtual_network_name}"
  25. location = "${var.location}"
  26. address_space = ["${var.address_space}"]
  27. resource_group_name = "${azurerm_resource_group.rg.name}"
  28. }
  29.  
  30. resource "azurerm_subnet" "subnet" {
  31. name = "${var.rg_prefix}subnet${count.index}"
  32. virtual_network_name = "${azurerm_virtual_network.vnet.name}"
  33. resource_group_name = "${azurerm_resource_group.rg.name}"
  34. address_prefix = "${var.subnet_prefix}"
  35. }
  36.  
  37. resource "azurerm_network_interface" "nic" {
  38. # name = "nic${var.rg_prefix}${count.index}"
  39. name = "primaryNic${count.index}"
  40. location = "${var.location}"
  41. resource_group_name = "${azurerm_resource_group.rg.name}"
  42. # count = 2
  43.  
  44. ip_configuration {
  45. name = "ipconfig${var.rg_prefix}${count.index}"
  46. subnet_id = "${azurerm_subnet.subnet.id}"
  47. private_ip_address_allocation = "dynamic"
  48. public_ip_address_id = "${azurerm_public_ip.pip.id}"
  49. }
  50.  
  51. tags {
  52. environment = "staging"
  53. }
  54.  
  55. }
  56.  
  57. resource "azurerm_virtual_machine" "vm" {
  58. name = "vm${count.index}"
  59. location = "${var.location}"
  60. resource_group_name = "${azurerm_resource_group.rg.name}"
  61. vm_size = "${var.vm_size}"
  62. network_interface_ids = ["${azurerm_network_interface.nic.id}"]
  63. delete_data_disks_on_termination = true
  64. delete_os_disk_on_termination = true
  65. count = 2
  66.  
  67. storage_image_reference {
  68. publisher = "${var.image_publisher}"
  69. offer = "${var.image_offer}"
  70. sku = "${var.image_sku}"
  71. version = "${var.image_version}"
  72. }
  73.  
  74. storage_os_disk {
  75. name = "${lookup(var.osdisk, count.index)}"
  76. create_option = "FromImage"
  77. }
  78.  
  79. os_profile {
  80. computer_name = "${lookup(var.hostname, count.index)}"
  81. admin_username = "${var.admin_username}"
  82. admin_password = "${var.admin_password}"
  83. }
  84.  
  85. os_profile_linux_config {
  86. disable_password_authentication = false
  87. }
  88. }
  89. data "azurerm_public_ip" "test" {
  90. name = "${azurerm_public_ip.pip.name}"
  91. resource_group_name = "${azurerm_resource_group.rg.name}"
  92. depends_on = ["azurerm_virtual_machine.vm"]
  93. }
  94.  
  95. resource "null_resource" "null" {
  96. provisioner "remote-exec" {
  97. inline = [
  98. "echo ${var.admin_password} | sudo -S hostnamectl set-hostname nels-sample1",
  99.  
  100. ]
  101.  
  102. connection {
  103. type = "ssh"
  104. agent = false
  105. host = "${data.azurerm_public_ip.test.ip_address}"
  106. user = "${var.admin_username}"
  107. password = "${var.admin_password}"
  108. timeout = "10m"
  109. }
  110. }
  111. }
  112. resource "azurerm_network_security_group" "nsg" {
  113. name = "nsg${var.resource_group}"
  114. location = "${var.location}"
  115. resource_group_name = "${azurerm_resource_group.rg.name}"
  116.  
  117. security_rule {
  118. name = "SSH_Officea1"
  119. priority = 1002
  120. direction = "Inbound"
  121. access = "Allow"
  122. protocol = "Tcp"
  123. source_port_range = "*"
  124. destination_port_range = "22"
  125. source_address_prefix = "*"
  126. destination_address_prefix = "*"
  127. }
  128.  
  129. tags {
  130. environment = "Public Cloud Nodes"
  131. }
  132.  
  133. security_rule {
  134. name = "SSH_Officeb2"
  135. priority = 1001
  136. direction = "Inbound"
  137. access = "Allow"
  138. protocol = "Tcp"
  139. source_port_range = "*"
  140. destination_port_range = "22"
  141. source_address_prefix = "*"
  142. destination_address_prefix = "*"
  143. }
  144.  
  145. tags {
  146. environment = "Public Cloud Nodes"
  147. }
  148. }
Add Comment
Please, Sign In to add comment