-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
139 lines (118 loc) · 4.22 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
provider "azurerm" {
version = "=2.28.0"
features {}
}
resource "random_string" "unique" {
length = 6
special = false
upper = false
}
resource "azurerm_resource_group" "rg" {
name = "rg-${random_string.unique.result}"
location = var.rg_location
}
resource "azurerm_databricks_workspace" "adb" {
name = "dbw-${random_string.unique.result}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
sku = "premium"
custom_parameters {
no_public_ip = false
virtual_network_id = azurerm_virtual_network.vnet.id
private_subnet_name = azurerm_subnet.adb_private.name
public_subnet_name = azurerm_subnet.adb_public.name
}
}
resource "azurerm_storage_account" "blob" {
name = "st${random_string.unique.result}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_container" "hdi" {
name = "hdinsight"
storage_account_name = azurerm_storage_account.blob.name
container_access_type = "private"
}
resource "random_password" "hdi" {
length = 10
min_upper = 1
min_lower = 1
min_numeric = 1
min_special = 1
override_special = "@#*()-_=+[]{}:?"
}
resource "azurerm_hdinsight_hbase_cluster" "hbase" {
name = "hbase-${random_string.unique.result}"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
cluster_version = "4.0"
tier = "Standard"
component_version {
hbase = "2.1"
}
gateway {
enabled = true
username = var.hdi_cluster_username
password = random_password.hdi.result
}
storage_account {
storage_container_id = azurerm_storage_container.hdi.id
storage_account_key = azurerm_storage_account.blob.primary_access_key
is_default = true
}
# The VM sizes were chosen to be cheapest possible for each role
roles {
head_node {
vm_size = "standard_e2s_v3"
virtual_network_id = azurerm_virtual_network.vnet.id
subnet_id = azurerm_subnet.hdi.id
username = var.hdi_ssh_username
password = random_password.hdi.result
}
worker_node {
vm_size = "standard_a2m_v2"
virtual_network_id = azurerm_virtual_network.vnet.id
subnet_id = azurerm_subnet.hdi.id
username = var.hdi_ssh_username
password = random_password.hdi.result
target_instance_count = 1
}
zookeeper_node {
vm_size = "standard_d1_v2"
virtual_network_id = azurerm_virtual_network.vnet.id
subnet_id = azurerm_subnet.hdi.id
username = var.hdi_ssh_username
password = random_password.hdi.result
}
}
}
locals {
setup_hbase = "${path.module}/setup_hbase.txt"
}
# The following script populates HBase with a sample table and uploads the hbase-site.xml config to blob storage
resource "null_resource" "setup_hbase" {
triggers = {
hbase_cluster = azurerm_hdinsight_hbase_cluster.hbase.id
setup_hbase = filesha1(local.setup_hbase)
azurerm_storage_container = azurerm_storage_container.hdi.id
}
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
environment = {
HDI_SSH_ENDPOINT = "${var.hdi_ssh_username}@${azurerm_hdinsight_hbase_cluster.hbase.ssh_endpoint}"
HDI_SSH_PASSWORD = random_password.hdi.result
SETUP_HBASE = file(local.setup_hbase)
}
command = <<EOF
set -Eeuo pipefail
sshpass -p "$HDI_SSH_PASSWORD" \
ssh -o StrictHostKeyChecking=no $HDI_SSH_ENDPOINT "echo -e \"$SETUP_HBASE\" | hbase shell -n"
sshpass -p "$HDI_SSH_PASSWORD" \
ssh -o StrictHostKeyChecking=no $HDI_SSH_ENDPOINT \
"hdfs dfs -copyFromLocal /etc/hbase/conf/hbase-site.xml wasbs://${azurerm_storage_container.hdi.name}@${azurerm_storage_account.blob.primary_blob_host}/"
EOF
}
depends_on = [azurerm_hdinsight_hbase_cluster.hbase]
}