-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
123 lines (98 loc) · 3.46 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
locals {
main_ssh_key_path = var.ssh_key_path
ssh_key_path_dr = var.ssh_key_path_dr != null ? var.ssh_key_path_dr : var.ssh_key_path
main_ssh_user = var.ssh_user
dr_ssh_user = var.ssh_user_dr != null ? var.ssh_user_dr : var.ssh_user
script_path = var.terraform_script_path_folder == null ? null : (join("/", [var.terraform_script_path_folder, "terraform_%RAND%.sh"]))
}
#################################
# Run HADR scripts
#################################
resource "null_resource" "exec_hadr_main" {
connection {
type = "ssh"
user = local.main_ssh_user
private_key = file(local.main_ssh_key_path)
host = var.dsf_main_ip
timeout = "5m"
bastion_host = var.proxy_info.proxy_address
bastion_private_key = try(file(var.proxy_info.proxy_private_ssh_key_path), "")
bastion_user = var.proxy_info.proxy_ssh_user
script_path = local.script_path
}
provisioner "remote-exec" {
inline = ["sudo $JSONAR_BASEDIR/bin/arbiter-setup setup-2hadr-replica-set --ipv4-address-main=${var.dsf_main_private_ip} --ipv4-address-dr=${var.dsf_dr_private_ip} --replication-sync-interval=30"]
}
}
resource "null_resource" "exec_hadr_dr" {
connection {
type = "ssh"
user = local.dr_ssh_user
private_key = file(local.ssh_key_path_dr)
host = var.dsf_dr_ip
timeout = "5m"
bastion_host = var.proxy_info.proxy_address
bastion_private_key = try(file(var.proxy_info.proxy_private_ssh_key_path), "")
bastion_user = var.proxy_info.proxy_ssh_user
script_path = local.script_path
}
provisioner "remote-exec" {
inline = ["sudo $JSONAR_BASEDIR/bin/arbiter-setup restart-secondary-services --disable-primary-check"]
}
depends_on = [
null_resource.exec_hadr_main
]
}
resource "time_sleep" "sleep_before_replication_cycle" {
create_duration = "1m"
depends_on = [
null_resource.exec_hadr_dr
]
}
resource "null_resource" "exec_replication_cycle_on_dr" {
connection {
type = "ssh"
user = local.dr_ssh_user
private_key = file(local.ssh_key_path_dr)
host = var.dsf_dr_ip
timeout = "5m"
bastion_host = var.proxy_info.proxy_address
bastion_private_key = try(file(var.proxy_info.proxy_private_ssh_key_path), "")
bastion_user = var.proxy_info.proxy_ssh_user
script_path = local.script_path
}
provisioner "remote-exec" {
inline = [
"sudo touch $JSONAR_LOGDIR/sonarw/replication.log",
"sudo chown sonarw:sonar $JSONAR_LOGDIR/sonarw/replication.log",
"sudo $JSONAR_BASEDIR/bin/arbiter-setup run-replication --no-tail"]
}
depends_on = [
time_sleep.sleep_before_replication_cycle
]
}
resource "time_sleep" "sleep_before_hadr_verify" {
create_duration = "10m"
depends_on = [
null_resource.exec_replication_cycle_on_dr
]
}
resource "null_resource" "hadr_verify" {
connection {
type = "ssh"
user = local.main_ssh_user
private_key = file(local.main_ssh_key_path)
host = var.dsf_main_ip
timeout = "5m"
bastion_host = var.proxy_info.proxy_address
bastion_private_key = try(file(var.proxy_info.proxy_private_ssh_key_path), "")
bastion_user = var.proxy_info.proxy_ssh_user
script_path = local.script_path
}
provisioner "remote-exec" {
inline = ["sudo $JSONAR_BASEDIR/bin/arbiter-setup check-2hadr-replica-set"]
}
depends_on = [
time_sleep.sleep_before_hadr_verify
]
}