-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
117 lines (104 loc) · 3.9 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
# ======================== bucket ============================
resource "google_storage_bucket" "weka_deployment" {
count = var.state_bucket_name == "" ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-${var.project_id}"
location = var.region
uniform_bucket_level_access = true
labels = {
goog-partner-solution = "isol_plb32_0014m00001h34hnqai_by7vmugtismizv6y46toim6jigajtrwh"
}
lifecycle {
precondition {
condition = length(var.prefix) + length(var.cluster_name) + length(var.project_id) <= 63
error_message = "The bucket name maximum allowed length is 63."
}
}
}
# ======================== instances ============================
locals {
private_nic_first_index = local.assign_public_ip ? 1 : 0
nics_number = var.nic_number != -1 ? var.nic_number : var.containers_config_map[var.machine_type].nics
disk_size = var.default_disk_size + var.traces_per_ionode * (var.containers_config_map[var.machine_type].compute + var.containers_config_map[var.machine_type].drive + var.containers_config_map[var.machine_type].frontend)
}
resource "google_compute_instance_template" "this" {
name = "${var.prefix}-${var.cluster_name}-backends"
machine_type = var.machine_type
can_ip_forward = false
tags = ["${var.prefix}-${var.cluster_name}-backends", "allow-health-check", "backends", "all-apis"]
labels = {
weka_cluster_name = var.cluster_name
goog-partner-solution = "isol_plb32_0014m00001h34hnqai_by7vmugtismizv6y46toim6jigajtrwh"
}
service_account {
email = local.sa_email
scopes = ["cloud-platform"]
}
disk {
source_image = var.source_image_id
boot = true
disk_type = var.boot_disk_type
}
disk {
device_name = var.default_disk_name
mode = "READ_WRITE"
disk_size_gb = local.disk_size
disk_type = "pd-ssd" # https://cloud.google.com/compute/docs/disks#disk-types
}
dynamic "disk" {
for_each = range(var.nvmes_number)
content {
interface = "NVME"
boot = false
type = "SCRATCH"
disk_type = "local-ssd"
disk_size_gb = 375
}
}
# nic with public ip
dynamic "network_interface" {
for_each = range(local.private_nic_first_index)
content {
nic_type = var.nic_type
subnetwork = data.google_compute_subnetwork.this[network_interface.value].name
subnetwork_project = local.network_project_id
access_config {}
}
}
# nics with private ip
dynamic "network_interface" {
for_each = range(local.private_nic_first_index, local.nics_number)
content {
nic_type = var.nic_type
subnetwork_project = local.network_project_id
subnetwork = data.google_compute_subnetwork.this[network_interface.value].name
}
}
metadata = {
ssh-keys = "${var.vm_username}:${local.ssh_public_key}"
}
lifecycle {
ignore_changes = [network_interface]
create_before_destroy = false
}
depends_on = [module.network, module.shared_vpc_peering]
}
# ======================== instance-group ============================
resource "google_compute_instance_group" "this" {
name = "${var.prefix}-${var.cluster_name}-instance-group"
zone = var.zone
network = data.google_compute_network.this[0].self_link
depends_on = [google_compute_region_health_check.health_check, module.network, module.shared_vpc_peering]
lifecycle {
ignore_changes = [network]
}
}
resource "google_compute_instance_group" "nfs" {
count = var.nfs_setup_protocol ? 1 : 0
name = "${var.prefix}-${var.cluster_name}-nfs-group"
zone = var.zone
network = data.google_compute_network.this[0].self_link
depends_on = [google_compute_region_health_check.health_check, module.network, module.shared_vpc_peering]
lifecycle {
ignore_changes = [network]
}
}