-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
127 lines (115 loc) · 3.93 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
/*
Setup VM | Public IP | Storage Disk
*/
locals {
# Will be removed in future commits
discovery_addresses = join(",", [for num in range(var.nodeCount) : format("%s%s", "http-forwardingrule-${var.env}-${num + 1}", ":5000")])
}
resource "google_compute_instance" "neo4j-gce" {
count = var.nodeCount
name = "${var.vm_name}-${var.env}-${count.index + 1}"
zone = var.zone
machine_type = var.machine_type
tags = var.firewall_target_tags
labels = {
"env" = var.env,
"group" = var.labels_group
}
network_interface {
network = google_compute_network.neo4j-network.id
subnetwork = google_compute_subnetwork.neo4j-subnetwork.id
access_config {
}
}
boot_disk {
initialize_params {
image = var.vm_os_image
size = var.neo4j_disk_size
type = var.neo4j_disk_type
labels = {
"env" = var.env,
"group" = var.labels_group
}
}
auto_delete = var.vm_boot_disk_delete_on_termination
}
# Update this as necessary to match your project and
# make sure update the `variables.tf` file to reflect
# your changes here.
allow_stopping_for_update = var.allow_stopping_for_update
scheduling {
preemptible = var.scheduling_preemptible
automatic_restart = var.scheduling_automatic_restart
}
lifecycle {
ignore_changes = [attached_disk]
}
/*
provisioner "file" {
source = "./scripts/core-5.sh"
destination = "/tmp/core-5.sh"
}
*/
metadata_startup_script = templatefile("./scripts/core-5.sh", {
#"forwarding-rule-name" = google_compute_forwarding_rule.neo4j-node-forwarding-rule.name
"forwarding_rule_name" = "neo4j-node-forwarding-rule-${var.env}"
"env" = var.env
"region" = var.region
"adminPassword" = var.adminPassword
"nodeCount" = var.nodeCount
"gdsNodeCount" = var.gdsNodeCount
"installGraphDataScience" = "No"
"graphDataScienceLicenseKey" = ""
"installBloom" = var.installBloom
"bloomLicenseKey" = var.bloomLicenseKey
})
service_account {
scopes = ["cloud-platform"]
}
# depends_on = [local_file.render_setup_template]
}
/*
Setup template renderer for validation of VM setup script
resource "local_file" "render_setup_template" {
count = var.nodeCount
filename = "./out/rendered_template_${count.index + 1}.sh"
content = templatefile("./scripts/core-5.sh", {
"network_name" = google_compute_network.neo4j-network.name
#"forwarding-rule-name" = google_compute_forwarding_rule.neo4j-node-forwarding-rule.name
"forwarding-rule-name" = "neo4j-node-forwarding-rule-${var.env}"
"env" = var.env
"region" = var.region
"graphDatabaseVersion" = var.neo4j_version
"adminPassword" = var.adminPassword
"nodeCount" = var.nodeCount
"gdsNodeCount" = var.gdsNodeCount
"installGraphDataScience" = "No"
"graphDataScienceLicenseKey" = ""
"installBloom" = var.installBloom
"bloomLicenseKey" = var.bloomLicenseKey
})
}
*/
/*
This block will support the creation of the storage disk for the Neo4j Datastore.
Note: If disk is resized need to execute the following command
inside the VM manually `sudo resize2fs </dev/sda>`
*/
resource "google_compute_disk" "disks" {
count = var.nodeCount
name = "neo4j-disk-${var.env}-${count.index + 1}"
size = var.neo4j_disk_size
type = var.neo4j_disk_type
zone = var.zone
labels = {
"env" = var.env
}
}
/*
Attach the disk created above to this VM
*/
resource "google_compute_attached_disk" "attach-disks" {
count = var.nodeCount
disk = google_compute_disk.disks[count.index].id
instance = google_compute_instance.neo4j-gce[count.index].id
}