-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
159 lines (135 loc) · 7.36 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
resource "shell_script" "auth" {
for_each = { for i in local.nodes : try(i.address, i.hostname) => i }
interpreter = ["${path.module}/ssh-wrapper.sh"]
lifecycle_commands {
create = "${path.module}/provisioner.sh create auth"
update = "${path.module}/provisioner.sh update auth"
read = "${path.module}/provisioner.sh read auth"
delete = "${path.module}/provisioner.sh delete auth"
}
environment = {
SSH_HOST = try(each.value.address, each.value.hostname)
SSH_USER = try(each.value.ssh_user, var.ssh_user)
SSH_PASSWORD = try(each.value.ssh_password, var.ssh_password)
SSH_PRIVATE_KEY = try(each.value.ssh_private_key, var.ssh_private_key)
SSH_PRIVATE_KEY_DATA = filebase64(try(each.value.ssh_private_key, var.ssh_private_key))
SSH_BASTION_HOST = var.ssh_bastion_host
SSH_BASTION_USER = var.ssh_bastion_user
SSH_BASTION_PASSWORD = var.ssh_bastion_password
SSH_BASTION_PRIVATE_KEY = var.ssh_bastion_private_key
SSH_BASTION_PRIVATE_KEY_DATA = var.ssh_bastion_private_key != "" ? filebase64(var.ssh_bastion_private_key) : ""
PROVISION_DEBUG = var.provision_debug
PROVISION_DATA_NODE_TYPE = each.value.node_type
PROVISION_DATA_DISKS = base64encode(jsonencode(each.value.disks))
}
}
resource "shell_script" "disks" {
for_each = { for i in local.nodes : try(i.address, i.hostname) => i }
depends_on = [shell_script.auth]
interpreter = ["${path.module}/ssh-wrapper.sh"]
lifecycle_commands {
create = "${path.module}/provisioner.sh create disks"
update = "${path.module}/provisioner.sh update disks"
read = "${path.module}/provisioner.sh read disks"
delete = "${path.module}/provisioner.sh delete disks"
}
environment = {
SSH_HOST = try(each.value.address, each.value.hostname)
SSH_USER = try(each.value.ssh_user, var.ssh_user)
SSH_PASSWORD = try(each.value.ssh_password, var.ssh_password)
SSH_PRIVATE_KEY = try(each.value.ssh_private_key, var.ssh_private_key)
SSH_PRIVATE_KEY_DATA = filebase64(try(each.value.ssh_private_key, var.ssh_private_key))
SSH_BASTION_HOST = var.ssh_bastion_host
SSH_BASTION_USER = var.ssh_bastion_user
SSH_BASTION_PASSWORD = var.ssh_bastion_password
SSH_BASTION_PRIVATE_KEY = var.ssh_bastion_private_key
SSH_BASTION_PRIVATE_KEY_DATA = var.ssh_bastion_private_key != "" ? filebase64(var.ssh_bastion_private_key) : ""
SUDO = "sudo"
PROVISION_DEBUG = var.provision_debug
PROVISION_DATA_NODE_TYPE = each.value.node_type
PROVISION_DATA_DISKS = base64encode(jsonencode(each.value.disks))
}
}
resource "shell_script" "packages" {
for_each = { for i in local.nodes : try(i.hostname, i.address) => i }
depends_on = [shell_script.disks]
interpreter = ["${path.module}/ssh-wrapper.sh"]
lifecycle_commands {
create = "${path.module}/provisioner.sh create packages"
update = "${path.module}/provisioner.sh update packages"
read = "${path.module}/provisioner.sh read packages"
delete = "${path.module}/provisioner.sh delete packages"
}
environment = {
SSH_HOST = try(each.value.address, each.value.hostname)
SSH_USER = try(each.value.ssh_user, var.ssh_user)
SSH_PASSWORD = try(each.value.ssh_password, var.ssh_password)
SSH_PRIVATE_KEY = try(each.value.ssh_private_key, var.ssh_private_key)
SSH_PRIVATE_KEY_DATA = filebase64(try(each.value.ssh_private_key, var.ssh_private_key))
SSH_BASTION_HOST = var.ssh_bastion_host
SSH_BASTION_USER = var.ssh_bastion_user
SSH_BASTION_PASSWORD = var.ssh_bastion_password
SSH_BASTION_PRIVATE_KEY = var.ssh_bastion_private_key
SSH_BASTION_PRIVATE_KEY_DATA = var.ssh_bastion_private_key != "" ? filebase64(var.ssh_bastion_private_key) : ""
SUDO = "sudo"
PROVISION_DEBUG = var.provision_debug
PROVISION_DATA_NODE_TYPE = each.value.node_type
PROVISION_DATA_INSTALL_PACKAGES = join(" ", sort(var.install_packages))
PROVISION_DATA_UNINSTALL_PACKAGES = join(" ", sort(var.uninstall_packages))
}
}
resource "shell_script" "systemctl" {
for_each = { for i in local.nodes : try(i.hostname, i.address) => i }
depends_on = [shell_script.packages]
interpreter = ["${path.module}/ssh-wrapper.sh"]
lifecycle_commands {
create = "${path.module}/provisioner.sh create systemctl"
update = "${path.module}/provisioner.sh update systemctl"
read = "${path.module}/provisioner.sh read systemctl"
delete = "${path.module}/provisioner.sh delete systemctl"
}
environment = {
SSH_HOST = try(each.value.address, each.value.hostname)
SSH_USER = try(each.value.ssh_user, var.ssh_user)
SSH_PASSWORD = try(each.value.ssh_password, var.ssh_password)
SSH_PRIVATE_KEY = try(each.value.ssh_private_key, var.ssh_private_key)
SSH_PRIVATE_KEY_DATA = filebase64(try(each.value.ssh_private_key, var.ssh_private_key))
SSH_BASTION_HOST = var.ssh_bastion_host
SSH_BASTION_USER = var.ssh_bastion_user
SSH_BASTION_PASSWORD = var.ssh_bastion_password
SSH_BASTION_PRIVATE_KEY = var.ssh_bastion_private_key
SSH_BASTION_PRIVATE_KEY_DATA = var.ssh_bastion_private_key != "" ? filebase64(var.ssh_bastion_private_key) : ""
SUDO = "sudo"
PROVISION_DEBUG = var.provision_debug
PROVISION_DATA_NODE_TYPE = each.value.node_type
PROVISION_DATA_SYSTEMCTL_ENABLE = join(" ", sort(var.systemctl_enable))
PROVISION_DATA_SYSTEMCTL_DISABLE = join(" ", sort(var.systemctl_disable))
}
}
resource "shell_script" "etc_hosts" {
for_each = { for i in local.nodes : try(i.address, i.hostname) => i }
depends_on = [shell_script.packages]
interpreter = ["${path.module}/ssh-wrapper.sh"]
lifecycle_commands {
create = "${path.module}/provisioner.sh create etc_hosts"
update = "${path.module}/provisioner.sh update etc_hosts"
read = "${path.module}/provisioner.sh read etc_hosts"
delete = "${path.module}/provisioner.sh delete etc_hosts"
}
environment = {
SSH_HOST = try(each.value.address, each.value.hostname)
SSH_USER = try(each.value.ssh_user, var.ssh_user)
SSH_PASSWORD = try(each.value.ssh_password, var.ssh_password)
SSH_PRIVATE_KEY = try(each.value.ssh_private_key, var.ssh_private_key)
SSH_PRIVATE_KEY_DATA = filebase64(try(each.value.ssh_private_key, var.ssh_private_key))
SSH_BASTION_HOST = var.ssh_bastion_host
SSH_BASTION_USER = var.ssh_bastion_user
SSH_BASTION_PASSWORD = var.ssh_bastion_password
SSH_BASTION_PRIVATE_KEY = var.ssh_bastion_private_key
SSH_BASTION_PRIVATE_KEY_DATA = var.ssh_bastion_private_key != "" ? filebase64(var.ssh_bastion_private_key) : ""
SUDO = "sudo"
PROVISION_DEBUG = var.provision_debug
PROVISION_DATA_NODE_TYPE = each.value.node_type
PROVISION_DATA_ETC_HOSTS = base64encode(jsonencode(var.etc_hosts))
}
}