-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.tf
59 lines (49 loc) · 1.46 KB
/
server.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
resource "google_compute_instance_template" "server" {
name_prefix = "hashi-server"
description = "Created with Terraform"
disk {
source_image = "${var.project}/${data.external.run_packer.result["server"]}"
auto_delete = true
boot = true
}
tags = var.tags
machine_type = var.server_machine_type
network_interface {
network = google_compute_network.default.name
access_config {
nat_ip = ""
network_tier = var.network_tier
}
}
service_account {
email = var.account_email
scopes = var.account_scopes
}
lifecycle {
create_before_destroy = true
}
metadata_startup_script = <<EOT
sudo pm2 start --wait-ready --listen-timeout 15000 /scripts/nomad.sh -- -bootstrap-expect=${var.server_target_size}
sudo pm2 start --wait-ready --listen-timeout 15000 /scripts/consul.sh -- "-bootstrap-expect ${var.server_target_size}"
EOT
}
resource "google_compute_instance_group_manager" "server" {
provider = "google-beta"
base_instance_name = "hashi-server"
name = "hashi-server-group-manager"
target_size = var.server_target_size
update_policy{
type = "PROACTIVE"
minimal_action = "REPLACE"
min_ready_sec = 120
max_unavailable_fixed = 1
max_surge_fixed = 1
}
version {
name = "default"
instance_template = google_compute_instance_template.server.self_link
}
lifecycle {
create_before_destroy = true
}
}