This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
162 lines (158 loc) · 5.02 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
160
161
162
terraform {
required_providers {
crusoe = {
source = "registry.terraform.io/crusoecloud/crusoe"
version = "0.5.10"
}
}
}
locals {
my_ssh_privkey_path = "~/.ssh/id_ed25519"
my_ssh_pubkey = "<SSH_PUBLIC_KEY>"
headnode_instance_type = "a40.1x"
deploy_location = "us-northcentral1-a"
}
resource "crusoe_storage_disk" "headnode_disk" {
name = "headnode-disk"
size = "512GiB"
location = local.deploy_location
}
resource "crusoe_compute_instance" "headnode_vm1" {
name = "crusoe-headnode-1"
type = local.headnode_instance_type
ssh_key = local.my_ssh_pubkey
location = local.deploy_location
image = "ubuntu22.04-nvidia-pcie-docker:latest"
disks = [{
id = crusoe_storage_disk.headnode_disk.id
mode = "read-write"
attachment_type = "data"
}
]
startup_script = file("headnode-bootstrap.sh")
network_interfaces = [{
# fetch subnet IDs via "crusoe networking vpc-subnets list"
subnet = "8dcb140f-5fd7-4c59-bb09-26e22af861dc"
}]
provisioner "file" {
content = local.my_ssh_pubkey
destination = "/root/provision.key"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "remote-exec" {
inline = [
"echo export CRUSOE_ACCESS_KEY_ID=${var.access_key} >> /etc/profile.d/crusoe-cli.sh",
"echo export CRUSOE_SECRET_KEY=${var.secret_key} >> /etc/profile.d/crusoe-cli.sh",
"echo export CRUSOE_SSH_PUBLIC_KEY_FILE=/root/provision.key >> /etc/profile.d/crusoe-cli.sh",
"chmod +x /etc/profile.d/crusoe-cli.sh"
]
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "local-exec" {
command = "crusoe compute vms get ${self.name} -f json >> /tmp/metadata.${self.name}.json"
}
provisioner "file" {
source = "/tmp/metadata.${self.name}.json"
destination = "/root/metadata.json"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "slurm-crusoe-startup.sh"
destination = "/tmp/slurm-crusoe-startup.sh"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "slurm-crusoe-shutdown.sh"
destination = "/tmp/slurm-crusoe-shutdown.sh"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "slurm.conf"
destination = "/tmp/slurm.conf"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "enroot/enroot.conf"
destination = "/tmp/enroot.conf"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "monitoring/telegraf.conf"
destination = "/tmp/telegraf.conf"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "monitoring/prometheus.yml"
destination = "/tmp/prometheus.yml"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "file" {
source = "monitoring/targets-prom.py"
destination = "/tmp/targets-prom.py"
connection {
type = "ssh"
user = "root"
host = self.network_interfaces[0].public_ipv4.address
private_key = file("${local.my_ssh_privkey_path}")
}
}
provisioner "local-exec" {
command = "rm -rf /tmp/metadata.${self.name}.json"
}
}
resource "crusoe_vpc_firewall_rule" "grafana_rule" {
network = crusoe_compute_instance.headnode_vm1.network_interfaces[0].network
name = "grafana-access"
action = "allow"
direction = "ingress"
protocols = "tcp"
source = "0.0.0.0/0"
source_ports = "1-65535"
destination = crusoe_compute_instance.headnode_vm1.network_interfaces[0].public_ipv4.address
destination_ports = "3000"
}