terraform/examples/azure-spark-and-cassandra-o.../main.tf

406 lines
16 KiB
Terraform
Raw Normal View History

provider/azurerm: Add example of Spark and Cassrandra on CentOS (#15123) * initial commit - 101-vm-from-user-image * changed branch name * not deploying - storage problems * provisions vm but image not properly prepared * storage not correct * provisions properly * changed main.tf to azuredeploy.tf * added tfvars and info for README * tfvars ignored and corrected file ext * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * deploy.sh to be executable * executable deploy files * added CI files; changed vars * prep for PR * removal of old folder * prep for PR * wrong args for travis * more PR prep * updated README * commented out variables in terraform.tfvars * Topic 101 vm from user image (#2) * initial commit - 101-vm-from-user-image * added tfvars and info for README * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * prep for PR * added new template * oops, left off master * prep for PR * correct repository for destination * renamed scripts to be more intuitive; added check for docker * merge vm simple; vm from image * initial commit * deploys locally * updated deploy * consolidated deploy and after_deploy into a single script; simplified ci process; added os_profile_linux_config * added terraform show * changed to allow http & https (like ARM tmplt) * changed host_name & host_name variable desc * added az cli check * on this branch, only build test_dir; master will aggregate all the examples * merge master * added new constructs/naming for deploy scripts, etc. * suppress az login output * suppress az login output * forgot about line breaks * breaking build as an example * fixing broken build example * merge of CI config * fixed grammar in readme * prep for PR * took out armviz button and minor README changes * changed host_name * fixed merge conflicts * changed host_name variable * updating Hashicorp's changes to merged simple linux branch * updating files to merge w/master and prep for Hashicorp pr * Revert "updating files to merge w/master and prep for Hashicorp pr" This reverts commit b850cd5d2a858eff073fc5a1097a6813d0f8b362. * Revert "updating Hashicorp's changes to merged simple linux branch" This reverts commit dbaf8d14a9cdfcef0281919671357f6171ebd4e6. * removing vm from user image example from this branch * removed old branch * azure-2-vms-loadbalancer-lbrules (#13) * initial commit * need to change lb_rule & nic * deploys locally * updated README * updated travis and deploy scripts for Hari's repo * renamed deploy script * clean up * prep for PR * updated readme * fixing conflict in .travis.yml * initial commit; in progress * in progress * in progress; encryption fails * in progress * deploys successfully locally * clean up; deploy typo fixed * merging hashi master into this branch * troubleshooting deploy * added missing vars to deploy script * updated README, outputs, and added graph * simplified outputs * provisions locally * cleaned up vars * fixed chart on README * prepping for pr * fixed merge conflict * switching to Hashicorp's .travis.yml * edited comments * removed graph * reverting travis.yml to original added return line at 45
2017-06-08 18:38:34 +02:00
# provider "azurerm" {
# subscription_id = "${var.subscription_id}"
# client_id = "${var.client_id}"
# client_secret = "${var.client_secret}"
# tenant_id = "${var.tenant_id}"
# }
resource "azurerm_resource_group" "rg" {
name = "${var.resource_group}"
location = "${var.location}"
}
# ********************** NETWORK SECURITY GROUPS ********************** #
resource "azurerm_network_security_group" "master" {
name = "${var.nsg_spark_master_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
security_rule {
name = "ssh"
description = "Allow SSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
security_rule {
name = "http_webui_spark"
description = "Allow Web UI Access to Spark"
priority = 101
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "8080"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
security_rule {
name = "http_rest_spark"
description = "Allow REST API Access to Spark"
priority = 102
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "6066"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
}
resource "azurerm_network_security_group" "slave" {
name = "${var.nsg_spark_slave_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
security_rule {
name = "ssh"
description = "Allow SSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
}
resource "azurerm_network_security_group" "cassandra" {
name = "${var.nsg_cassandra_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
security_rule {
name = "ssh"
description = "Allow SSH"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
}
# ********************** VNET / SUBNETS ********************** #
resource "azurerm_virtual_network" "spark" {
name = "vnet-spark"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
address_space = ["${var.vnet_spark_prefix}"]
}
resource "azurerm_subnet" "subnet1" {
name = "${var.vnet_spark_subnet1_name}"
virtual_network_name = "${azurerm_virtual_network.spark.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${var.vnet_spark_subnet1_prefix}"
network_security_group_id = "${azurerm_network_security_group.master.id}"
depends_on = ["azurerm_virtual_network.spark"]
}
resource "azurerm_subnet" "subnet2" {
name = "${var.vnet_spark_subnet2_name}"
virtual_network_name = "${azurerm_virtual_network.spark.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${var.vnet_spark_subnet2_prefix}"
}
resource "azurerm_subnet" "subnet3" {
name = "${var.vnet_spark_subnet3_name}"
virtual_network_name = "${azurerm_virtual_network.spark.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${var.vnet_spark_subnet3_prefix}"
}
# ********************** PUBLIC IP ADDRESSES ********************** #
resource "azurerm_public_ip" "master" {
name = "${var.public_ip_master_name}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "Static"
}
resource "azurerm_public_ip" "slave" {
name = "${var.public_ip_slave_name_prefix}${count.index}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "Static"
count = "${var.vm_number_of_slaves}"
}
resource "azurerm_public_ip" "cassandra" {
name = "${var.public_ip_cassandra_name}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "Static"
}
# ********************** NETWORK INTERFACE ********************** #
resource "azurerm_network_interface" "master" {
name = "${var.nic_master_name}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_security_group_id = "${azurerm_network_security_group.master.id}"
depends_on = ["azurerm_virtual_network.spark", "azurerm_public_ip.master", "azurerm_network_security_group.master"]
ip_configuration {
name = "ipconfig1"
subnet_id = "${azurerm_subnet.subnet1.id}"
private_ip_address_allocation = "Static"
private_ip_address = "${var.nic_master_node_ip}"
public_ip_address_id = "${azurerm_public_ip.master.id}"
}
}
resource "azurerm_network_interface" "slave" {
name = "${var.nic_slave_name_prefix}${count.index}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_security_group_id = "${azurerm_network_security_group.slave.id}"
count = "${var.vm_number_of_slaves}"
depends_on = ["azurerm_virtual_network.spark", "azurerm_public_ip.slave", "azurerm_network_security_group.slave"]
ip_configuration {
name = "ipconfig1"
subnet_id = "${azurerm_subnet.subnet2.id}"
private_ip_address_allocation = "Static"
private_ip_address = "${var.nic_slave_node_ip_prefix}${5 + count.index}"
public_ip_address_id = "${element(azurerm_public_ip.slave.*.id, count.index)}"
}
}
resource "azurerm_network_interface" "cassandra" {
name = "${var.nic_cassandra_name}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_security_group_id = "${azurerm_network_security_group.cassandra.id}"
depends_on = ["azurerm_virtual_network.spark", "azurerm_public_ip.cassandra", "azurerm_network_security_group.cassandra"]
ip_configuration {
name = "ipconfig1"
subnet_id = "${azurerm_subnet.subnet3.id}"
private_ip_address_allocation = "Static"
private_ip_address = "${var.nic_cassandra_node_ip}"
public_ip_address_id = "${azurerm_public_ip.cassandra.id}"
}
}
# ********************** AVAILABILITY SET ********************** #
resource "azurerm_availability_set" "slave" {
name = "${var.availability_slave_name}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
platform_update_domain_count = 5
platform_fault_domain_count = 2
}
# ********************** STORAGE ACCOUNTS ********************** #
resource "azurerm_storage_account" "master" {
name = "master${var.unique_prefix}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
account_type = "${var.storage_master_type}"
}
resource "azurerm_storage_container" "master" {
name = "${var.vm_master_storage_account_container_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.master.name}"
container_access_type = "private"
depends_on = ["azurerm_storage_account.master"]
}
resource "azurerm_storage_account" "slave" {
name = "slave${var.unique_prefix}${count.index}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
count = "${var.vm_number_of_slaves}"
account_type = "${var.storage_slave_type}"
}
resource "azurerm_storage_container" "slave" {
name = "${var.vm_slave_storage_account_container_name}${count.index}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${element(azurerm_storage_account.slave.*.name, count.index)}"
container_access_type = "private"
depends_on = ["azurerm_storage_account.slave"]
}
resource "azurerm_storage_account" "cassandra" {
name = "cassandra${var.unique_prefix}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
account_type = "${var.storage_cassandra_type}"
}
resource "azurerm_storage_container" "cassandra" {
name = "${var.vm_cassandra_storage_account_container_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.cassandra.name}"
container_access_type = "private"
depends_on = ["azurerm_storage_account.cassandra"]
}
# ********************** MASTER VIRTUAL MACHINE ********************** #
resource "azurerm_virtual_machine" "master" {
name = "${var.vm_master_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
vm_size = "${var.vm_master_vm_size}"
network_interface_ids = ["${azurerm_network_interface.master.id}"]
depends_on = ["azurerm_storage_account.master", "azurerm_network_interface.master", "azurerm_storage_container.master"]
storage_image_reference {
publisher = "${var.os_image_publisher}"
offer = "${var.os_image_offer}"
sku = "${var.os_version}"
version = "latest"
}
storage_os_disk {
name = "${var.vm_master_os_disk_name}"
vhd_uri = "http://${azurerm_storage_account.master.name}.blob.core.windows.net/${azurerm_storage_container.master.name}/${var.vm_master_os_disk_name}.vhd"
create_option = "FromImage"
caching = "ReadWrite"
}
os_profile {
computer_name = "${var.vm_master_name}"
admin_username = "${var.vm_admin_username}"
admin_password = "${var.vm_admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
connection {
type = "ssh"
host = "${azurerm_public_ip.master.ip_address}"
user = "${var.vm_admin_username}"
password = "${var.vm_admin_password}"
}
provisioner "remote-exec" {
inline = [
"wget ${var.artifacts_location}${var.script_spark_provisioner_script_file_name}",
"echo ${var.vm_admin_password} | sudo -S sh ./${var.script_spark_provisioner_script_file_name} -runas=master -master=${var.nic_master_node_ip}",
]
}
}
# ********************** SLAVE VIRTUAL MACHINES ********************** #
resource "azurerm_virtual_machine" "slave" {
name = "${var.vm_slave_name_prefix}${count.index}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
vm_size = "${var.vm_slave_vm_size}"
network_interface_ids = ["${element(azurerm_network_interface.slave.*.id, count.index)}"]
count = "${var.vm_number_of_slaves}"
availability_set_id = "${azurerm_availability_set.slave.id}"
depends_on = ["azurerm_storage_account.slave", "azurerm_network_interface.slave", "azurerm_storage_container.slave"]
storage_image_reference {
publisher = "${var.os_image_publisher}"
offer = "${var.os_image_offer}"
sku = "${var.os_version}"
version = "latest"
}
storage_os_disk {
name = "${var.vm_slave_os_disk_name_prefix}${count.index}"
vhd_uri = "http://${element(azurerm_storage_account.slave.*.name, count.index)}.blob.core.windows.net/${element(azurerm_storage_container.slave.*.name, count.index)}/${var.vm_slave_os_disk_name_prefix}.vhd"
create_option = "FromImage"
caching = "ReadWrite"
}
os_profile {
computer_name = "${var.vm_slave_name_prefix}${count.index}"
admin_username = "${var.vm_admin_username}"
admin_password = "${var.vm_admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
connection {
type = "ssh"
host = "${element(azurerm_public_ip.slave.*.ip_address, count.index)}"
user = "${var.vm_admin_username}"
password = "${var.vm_admin_password}"
}
provisioner "remote-exec" {
inline = [
"wget ${var.artifacts_location}${var.script_spark_provisioner_script_file_name}",
"echo ${var.vm_admin_password} | sudo -S sh ./${var.script_spark_provisioner_script_file_name} -runas=slave -master=${var.nic_master_node_ip}",
]
}
}
# ********************** CASSANDRA VIRTUAL MACHINE ********************** #
resource "azurerm_virtual_machine" "cassandra" {
name = "${var.vm_cassandra_name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${azurerm_resource_group.rg.location}"
vm_size = "${var.vm_cassandra_vm_size}"
network_interface_ids = ["${azurerm_network_interface.cassandra.id}"]
depends_on = ["azurerm_storage_account.cassandra", "azurerm_network_interface.cassandra", "azurerm_storage_container.cassandra"]
storage_image_reference {
publisher = "${var.os_image_publisher}"
offer = "${var.os_image_offer}"
sku = "${var.os_version}"
version = "latest"
}
storage_os_disk {
name = "${var.vm_cassandra_os_disk_name}"
vhd_uri = "http://${azurerm_storage_account.cassandra.name}.blob.core.windows.net/${azurerm_storage_container.cassandra.name}/${var.vm_cassandra_os_disk_name}.vhd"
create_option = "FromImage"
caching = "ReadWrite"
}
os_profile {
computer_name = "${var.vm_cassandra_name}"
admin_username = "${var.vm_admin_username}"
admin_password = "${var.vm_admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
connection {
type = "ssh"
host = "${azurerm_public_ip.cassandra.ip_address}"
user = "${var.vm_admin_username}"
password = "${var.vm_admin_password}"
}
provisioner "remote-exec" {
inline = [
"wget ${var.artifacts_location}${var.script_cassandra_provisioner_script_file_name}",
"echo ${var.vm_admin_password} | sudo -S sh ./${var.script_cassandra_provisioner_script_file_name}",
]
}
}