Skip to content

Commit

Permalink
add mycelium network to terraform examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Sep 26, 2024
1 parent 2baf7d7 commit fca7e5b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
15 changes: 15 additions & 0 deletions examples/resources/cosmosvalidator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ terraform {
provider "grid" {
}

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

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

resource "grid_scheduler" "sched" {
requests {
Expand All @@ -33,6 +40,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["node1"]) = random_bytes.mycelium_key.hex
}
}
resource "grid_deployment" "d1" {
solution_type = local.solution_type
Expand All @@ -46,6 +56,7 @@ resource "grid_deployment" "d1" {
publicip = true
memory = 4096
entrypoint = "/sbin/zinit init"
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")

Expand Down Expand Up @@ -74,3 +85,7 @@ output "node1_zmachine1_ip" {
output "ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
}

output "mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
4 changes: 4 additions & 0 deletions examples/resources/disks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ output "zdb1_endpoint" {
output "zdb1_namespace" {
value = grid_deployment.d1.zdbs[0].namespace
}

output "zdb1_mycelium_ip" {
value = grid_deployment.d1.zdbs[0].ips[2]
}
15 changes: 15 additions & 0 deletions examples/resources/expose-vm/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 = "node1"
Expand Down Expand Up @@ -45,6 +53,9 @@ resource "grid_network" "net1" {
name = local.name
description = "newer network"
add_wg_access = true
mycelium_keys = {
format("%s", local.node1) = random_bytes.mycelium_key.hex
}
}
resource "grid_deployment" "d1" {
name = local.name
Expand All @@ -59,6 +70,7 @@ resource "grid_deployment" "d1" {
env_vars = {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
planetary = true
}
}
Expand All @@ -82,3 +94,6 @@ output "ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
}

output "mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}
27 changes: 19 additions & 8 deletions examples/resources/gpu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ terraform {
provider "grid" {
}

locals {
name = "testvm"
resource "random_bytes" "mycelium_ip_seed" {
length = 6
}

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

locals {
name = "testvm"
node_id = 93
}

resource "grid_network" "net1" {
name = local.name
nodes = [93]
nodes = [local.node_id]
ip_range = "10.1.0.0/16"
description = "newer network"
mycelium_keys = {
format("%s", local.node_id) = random_bytes.mycelium_key.hex
}
}
resource "grid_deployment" "d1" {
name = local.name
node = 93
node = local.node_id
network_name = grid_network.net1.name
disks {
name = "data"
Expand All @@ -38,10 +49,10 @@ resource "grid_deployment" "d1" {
SSH_KEY = file("~/.ssh/id_rsa.pub")
}
mounts {
name = "data"
disk_name = "data"
mount_point = "/app"
}
planetary = true
mycelium_ip_seed = random_bytes.mycelium_ip_seed.hex
gpus = [
"0000:0e:00.0/1002/744c" //choose the correct gpu id available on the node your are deploying on
]
Expand All @@ -52,7 +63,7 @@ resource "grid_deployment" "d1" {
output "vm1_ip" {
value = grid_deployment.d1.vms[0].ip
}
output "vm1_ygg_ip" {
value = grid_deployment.d1.vms[0].planetary_ip
output "vm1_mycelium_ip" {
value = grid_deployment.d1.vms[0].mycelium_ip
}

0 comments on commit fca7e5b

Please sign in to comment.