Skip to content

Commit

Permalink
update terraform examples, add mycelium network to all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Sep 29, 2024
1 parent 2536e74 commit 5146c08
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 105 deletions.
2 changes: 1 addition & 1 deletion examples/resources/gpu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ resource "grid_deployment" "d1" {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
mounts {
disk_name = "data"
name = "data"
mount_point = "/app"
}
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
Expand Down
18 changes: 14 additions & 4 deletions examples/resources/mattermost/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ terraform {
}
}
}
resource "random_bytes" "mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "mycelium_key" {
length = 32
}

locals {
solution_type = "Mattermost"
Expand Down Expand Up @@ -36,6 +43,9 @@ resource "grid_network" "net1" {
ip_range = "10.1.0.0/16"
description = "newer network"
add_wg_access = true
mycelium_keys = {
format("%s", grid_scheduler.sched.nodes["node"]) = random_bytes.mycelium_key.hex
}
}

resource "grid_deployment" "d1" {
Expand All @@ -58,7 +68,7 @@ resource "grid_deployment" "d1" {
SMTPSERVER = "smtp.gmail.com"
SMTPPORT = 587
}
planetary = true
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
}
}

Expand All @@ -76,7 +86,7 @@ resource "grid_name_proxy" "p1" {
solution_type = local.solution_type
name = local.name
node = grid_scheduler.sched.nodes["gateway"]
backends = [format("http://[%s]:8000", grid_deployment.d1.vms[0].planetary_ip)]
backends = [format("http://[%s]:8000", grid_deployment.d1.vms[0].mycelium_ip)]
tls_passthrough = false
}

Expand All @@ -88,6 +98,6 @@ output "node1_zmachine1_ip" {
value = grid_deployment.d1.vms[0].ip
}

output "ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
output "mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
41 changes: 30 additions & 11 deletions examples/resources/mounts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ terraform {
provider "grid" {
}

resource "random_bytes" "mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "mycelium_key" {
length = 32
}

locals {
name = "mountdeployment"
}
Expand All @@ -28,6 +36,9 @@ resource "grid_network" "net1" {
ip_range = "10.1.0.0/16"
name = local.name
description = "newer network"
mycelium_keys = {
format("%s", grid_scheduler.sched.nodes["node1"]) = random_bytes.mycelium_key.hex
}
}

resource "grid_deployment" "d1" {
Expand All @@ -40,12 +51,13 @@ resource "grid_deployment" "d1" {
description = "volume holding app data"
}
vms {
name = "vm1"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
publicip = true
memory = 1024
entrypoint = "/sbin/zinit init"
name = "vm1"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
publicip = true
memory = 1024
entrypoint = "/sbin/zinit init"
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
mounts {
name = "data"
mount_point = "/app"
Expand All @@ -55,11 +67,12 @@ resource "grid_deployment" "d1" {
}
}
vms {
name = "anothervm"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
memory = 1024
entrypoint = "/sbin/zinit init"
name = "anothervm"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
memory = 1024
entrypoint = "/sbin/zinit init"
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
Expand All @@ -74,6 +87,12 @@ output "node1_zmachine1_ip" {
output "node1_zmachine2_ip" {
value = grid_deployment.d1.vms[1].ip
}
output "node1_zmachine1_mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
output "node1_zmachine2_mycelium_ip" {
value = grid_deployment.d1.vms[1].mycelium_ip
}
output "computed_public_ip" {
value = grid_deployment.d1.vms[0].computedip
}
52 changes: 40 additions & 12 deletions examples/resources/multinode/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ terraform {
provider "grid" {
}

resource "random_bytes" "d1_mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "d2_mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "d1_mycelium_key" {
length = 32
}

resource "random_bytes" "d2_mycelium_key" {
length = 32
}

locals {
name = "multinodedeployment"
}
Expand Down Expand Up @@ -37,19 +53,24 @@ resource "grid_network" "net1" {
ip_range = "172.20.0.0/16"
name = local.name
description = "new network"
mycelium_keys = {
format("%s", grid_scheduler.sched.nodes["node1"]) = random_bytes.d1_mycelium_key.hex
format("%s", grid_scheduler.sched.nodes["node2"]) = random_bytes.d2_mycelium_key.hex
}
}

resource "grid_deployment" "d1" {
name = local.name
node = grid_scheduler.sched.nodes["node1"]
network_name = grid_network.net1.name
vms {
name = "vm1"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 2
memory = 1024
publicip = true
entrypoint = "/sbin/zinit init"
name = "vm1"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 2
memory = 1024
publicip = true
entrypoint = "/sbin/zinit init"
mycelium_ip_seed = random_bytes.d1_mycelium_ip_seed.hex
env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
Expand All @@ -60,12 +81,13 @@ resource "grid_deployment" "d2" {
node = grid_scheduler.sched.nodes["node2"]
network_name = grid_network.net1.name
vms {
name = "vm2"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
memory = 1024
publicip = true
entrypoint = "/sbin/zinit init"
name = "vm2"
flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"
cpu = 1
memory = 1024
publicip = true
entrypoint = "/sbin/zinit init"
mycelium_ip_seed = random_bytes.d2_mycelium_ip_seed.hex
env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
Expand All @@ -78,11 +100,17 @@ output "node1_zmachine1_ip" {
output "node1_zmachine_computed_public_ip" {
value = grid_deployment.d1.vms[0].computedip
}
output "node1_zmachine_mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}

output "node2_zmachine1_ip" {
value = grid_deployment.d2.vms[0].ip
}
output "node2_zmachine_computed_public_ip" {
value = grid_deployment.d2.vms[0].computedip
}
output "node2_zmachine_mycelium_ip" {
value = grid_deployment.d2.vms[0].mycelium_ip
}

25 changes: 18 additions & 7 deletions examples/resources/nixos-micro/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ terraform {
provider "grid" {
}

resource "random_bytes" "mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "mycelium_key" {
length = 32
}

locals {
name = "myvm"
name = "myvm"
node_id = 11
}

resource "grid_network" "net1" {
name = local.name
nodes = [34]
nodes = [local.node_id]
ip_range = "10.1.0.0/16"
description = "newer network"
# add_wg_access = true
mycelium_keys = {
format("%s", local.node_id) = random_bytes.mycelium_key.hex
}
}
resource "grid_deployment" "d1" {
node = 34
node = local.node_id
network_name = grid_network.net1.name
disks {
name = "store"
Expand All @@ -39,6 +51,7 @@ resource "grid_deployment" "d1" {
name = "store"
mount_point = "/nix"
}
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex

env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")
Expand All @@ -56,8 +69,6 @@ pkgs.mkShell {
}
EOT
}

planetary = true
}
}

Expand All @@ -71,6 +82,6 @@ output "computed_public_ip" {
value = split("/", grid_deployment.d1.vms[0].computedip)[0]
}

output "ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
output "mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
25 changes: 18 additions & 7 deletions examples/resources/peertube/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ terraform {
provider "grid" {
}

resource "random_bytes" "mycelium_ip_seed" {
length = 6
}

resource "random_bytes" "mycelium_key" {
length = 32
}

resource "grid_scheduler" "sched" {
requests {
name = "peertube"
Expand Down Expand Up @@ -43,12 +51,15 @@ data "grid_gateway_domain" "domain" {
resource "grid_network" "net1" {
solution_type = local.solution_type
name = local.name
nodes = [grid_scheduler.sched.nodes["peertube"]]
nodes = [local.node]
ip_range = "10.1.0.0/16"
description = "peertube network"
mycelium_keys = {
format("%s", local.node) = random_bytes.mycelium_key.hex
}
}
resource "grid_deployment" "d1" {
node = grid_scheduler.sched.nodes["peertube"]
node = local.node
solution_type = local.solution_type
name = local.name
network_name = grid_network.net1.name
Expand All @@ -71,26 +82,26 @@ resource "grid_deployment" "d1" {
PEERTUBE_SMTP_PASSWORD = "sendgridpassword"
PEERTUBE_BIND_ADDRESS = "::",
}
planetary = true
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
}
}

locals {
ygg_ip = try(length(grid_deployment.d1.vms[0].planetary_ip), 0) > 0 ? grid_deployment.d1.vms[0].planetary_ip : ""
mycelium_ip = try(length(grid_deployment.d1.vms[0].mycelium_ip), 0) > 0 ? grid_deployment.d1.vms[0].mycelium_ip: ""
}

resource "grid_name_proxy" "p1" {
node = grid_scheduler.sched.nodes["domain"]
solution_type = local.solution_type
name = local.name
backends = [format("http://[%s]:9000", local.ygg_ip)]
backends = [format("http://[%s]:9000", local.mycelium_ip)]
tls_passthrough = false
}

output "fqdn" {
value = data.grid_gateway_domain.domain.fqdn
}

output "ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
output "mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
Loading

0 comments on commit 5146c08

Please sign in to comment.