github.com/bigcommerce/nomad@v0.9.3-bc/terraform/azure/modules/hashistack/hashistack.tf (about) 1 variable "location" {} 2 variable "image_id" {} 3 variable "vm_size" {} 4 variable "server_count" {} 5 variable "client_count" {} 6 variable "retry_join" {} 7 8 resource "tls_private_key" "main" { 9 algorithm = "RSA" 10 } 11 12 resource "null_resource" "main" { 13 provisioner "local-exec" { 14 command = "echo \"${tls_private_key.main.private_key_pem}\" > azure-hashistack.pem" 15 } 16 17 provisioner "local-exec" { 18 command = "chmod 600 azure-hashistack.pem" 19 } 20 } 21 22 resource "azurerm_resource_group" "hashistack" { 23 name = "hashistack" 24 location = "${var.location}" 25 } 26 27 resource "azurerm_virtual_network" "hashistack-vn" { 28 name = "hashistack-vn" 29 address_space = ["10.0.0.0/16"] 30 location = "${var.location}" 31 resource_group_name = "${azurerm_resource_group.hashistack.name}" 32 } 33 34 resource "azurerm_subnet" "hashistack-sn" { 35 name = "hashistack-sn" 36 resource_group_name = "${azurerm_resource_group.hashistack.name}" 37 virtual_network_name = "${azurerm_virtual_network.hashistack-vn.name}" 38 address_prefix = "10.0.2.0/24" 39 } 40 41 resource "azurerm_network_security_group" "hashistack-sg" { 42 name = "hashistack-sg" 43 location = "${var.location}" 44 resource_group_name = "${azurerm_resource_group.hashistack.name}" 45 } 46 47 resource "azurerm_network_security_rule" "hashistack-sgr-22" { 48 name = "hashistack-sgr-22" 49 resource_group_name = "${azurerm_resource_group.hashistack.name}" 50 network_security_group_name = "${azurerm_network_security_group.hashistack-sg.name}" 51 52 priority = 100 53 direction = "Inbound" 54 access = "Allow" 55 protocol = "Tcp" 56 57 source_address_prefix = "*" 58 source_port_range = "*" 59 destination_port_range = "22" 60 destination_address_prefix = "*" 61 } 62 63 resource "azurerm_network_security_rule" "hashistack-sgr-4646" { 64 name = "hashistack-sgr-4646" 65 resource_group_name = "${azurerm_resource_group.hashistack.name}" 66 network_security_group_name = "${azurerm_network_security_group.hashistack-sg.name}" 67 68 priority = 101 69 direction = "Inbound" 70 access = "Allow" 71 protocol = "Tcp" 72 73 source_address_prefix = "*" 74 source_port_range = "*" 75 destination_port_range = "4646" 76 destination_address_prefix = "*" 77 } 78 79 resource "azurerm_network_security_rule" "hashistack-sgr-8500" { 80 name = "hashistack-sgr-8500" 81 resource_group_name = "${azurerm_resource_group.hashistack.name}" 82 network_security_group_name = "${azurerm_network_security_group.hashistack-sg.name}" 83 84 priority = 102 85 direction = "Inbound" 86 access = "Allow" 87 protocol = "Tcp" 88 89 source_address_prefix = "*" 90 source_port_range = "*" 91 destination_port_range = "8500" 92 destination_address_prefix = "*" 93 } 94 95 resource "azurerm_public_ip" "hashistack-server-public-ip" { 96 count = "${var.server_count}" 97 name = "hashistack-server-ip-${count.index}" 98 location = "${var.location}" 99 resource_group_name = "${azurerm_resource_group.hashistack.name}" 100 public_ip_address_allocation = "static" 101 } 102 103 resource "azurerm_network_interface" "hashistack-server-ni" { 104 count = "${var.server_count}" 105 name = "hashistack-server-ni-${count.index}" 106 location = "${var.location}" 107 resource_group_name = "${azurerm_resource_group.hashistack.name}" 108 network_security_group_id = "${azurerm_network_security_group.hashistack-sg.id}" 109 110 ip_configuration { 111 name = "hashistack-ipc" 112 subnet_id = "${azurerm_subnet.hashistack-sn.id}" 113 private_ip_address_allocation = "dynamic" 114 public_ip_address_id = "${element(azurerm_public_ip.hashistack-server-public-ip.*.id,count.index)}" 115 } 116 117 tags { 118 ConsulAutoJoin = "auto-join" 119 } 120 } 121 122 resource "azurerm_virtual_machine" "server" { 123 name = "hashistack-server-${count.index}" 124 location = "${var.location}" 125 resource_group_name = "${azurerm_resource_group.hashistack.name}" 126 network_interface_ids = ["${element(azurerm_network_interface.hashistack-server-ni.*.id,count.index)}"] 127 vm_size = "${var.vm_size}" 128 count = "${var.server_count}" 129 130 # Uncomment this line to delete the OS disk automatically when deleting the VM 131 delete_os_disk_on_termination = true 132 133 # Uncomment this line to delete the data disks automatically when deleting the VM 134 delete_data_disks_on_termination = true 135 136 storage_image_reference { 137 id = "${var.image_id}" 138 } 139 140 storage_os_disk { 141 name = "hashistack-server-osdisk-${count.index}" 142 caching = "ReadWrite" 143 create_option = "FromImage" 144 managed_disk_type = "Standard_LRS" 145 } 146 147 os_profile { 148 computer_name = "hashistack-server-${count.index}" 149 admin_username = "ubuntu" 150 admin_password = "none" 151 custom_data = "${base64encode(data.template_file.user_data_server.rendered)}" 152 } 153 154 os_profile_linux_config { 155 disable_password_authentication = true 156 157 ssh_keys { 158 path = "/home/ubuntu/.ssh/authorized_keys" 159 key_data = "${tls_private_key.main.public_key_openssh}" 160 } 161 } 162 } 163 164 data "template_file" "user_data_server" { 165 template = "${file("${path.root}/user-data-server.sh")}" 166 167 vars { 168 server_count = "${var.server_count}" 169 retry_join = "${var.retry_join}" 170 } 171 } 172 173 resource "azurerm_public_ip" "hashistack-client-public-ip" { 174 count = "${var.client_count}" 175 name = "hashistack-client-ip-${count.index}" 176 location = "${var.location}" 177 resource_group_name = "${azurerm_resource_group.hashistack.name}" 178 public_ip_address_allocation = "static" 179 } 180 181 resource "azurerm_network_interface" "hashistack-client-ni" { 182 count = "${var.client_count}" 183 name = "hashistack-client-ni-${count.index}" 184 location = "${var.location}" 185 resource_group_name = "${azurerm_resource_group.hashistack.name}" 186 network_security_group_id = "${azurerm_network_security_group.hashistack-sg.id}" 187 188 ip_configuration { 189 name = "hashistack-ipc" 190 subnet_id = "${azurerm_subnet.hashistack-sn.id}" 191 private_ip_address_allocation = "dynamic" 192 public_ip_address_id = "${element(azurerm_public_ip.hashistack-client-public-ip.*.id,count.index)}" 193 } 194 195 tags { 196 ConsulAutoJoin = "auto-join" 197 } 198 } 199 200 resource "azurerm_virtual_machine" "client" { 201 name = "hashistack-client-${count.index}" 202 location = "${var.location}" 203 resource_group_name = "${azurerm_resource_group.hashistack.name}" 204 network_interface_ids = ["${element(azurerm_network_interface.hashistack-client-ni.*.id,count.index)}"] 205 vm_size = "${var.vm_size}" 206 count = "${var.client_count}" 207 depends_on = ["azurerm_virtual_machine.server"] 208 209 # Uncomment this line to delete the OS disk automatically when deleting the VM 210 delete_os_disk_on_termination = true 211 212 # Uncomment this line to delete the data disks automatically when deleting the VM 213 delete_data_disks_on_termination = true 214 215 storage_image_reference { 216 id = "${var.image_id}" 217 } 218 219 storage_os_disk { 220 name = "hashistack-client-osdisk-${count.index}" 221 caching = "ReadWrite" 222 create_option = "FromImage" 223 managed_disk_type = "Standard_LRS" 224 } 225 226 os_profile { 227 computer_name = "hashistack-client-${count.index}" 228 admin_username = "ubuntu" 229 admin_password = "none" 230 custom_data = "${base64encode(data.template_file.user_data_client.rendered)}" 231 } 232 233 os_profile_linux_config { 234 disable_password_authentication = true 235 236 ssh_keys { 237 path = "/home/ubuntu/.ssh/authorized_keys" 238 key_data = "${tls_private_key.main.public_key_openssh}" 239 } 240 } 241 } 242 243 data "template_file" "user_data_client" { 244 template = "${file("${path.root}/user-data-client.sh")}" 245 246 vars { 247 retry_join = "${var.retry_join}" 248 } 249 } 250 251 output "server_public_ips" { 252 value = ["${azurerm_public_ip.hashistack-server-public-ip.*.ip_address}"] 253 } 254 255 output "client_public_ips" { 256 value = ["${azurerm_public_ip.hashistack-client-public-ip.*.ip_address}"] 257 }