Development machine on TFGrid from Terraform

Idea

  • easy way & fast to get my development machine with
    • codeserver = editor
    • vlang
    • nodejs
  • I connect over planetary network to do my work, which is awesome
  • I was doing all of this with Gitpod, but now I am using this
 terraform {
  required_providers {
    grid = {
      source = "threefoldtech/grid"
    }
  }
}


provider "grid" {
    mnemonics = "THIS YOU NEED TO FILL IN" 
    network = "test" # or test to use testnet
}

resource "grid_network" "net1" {
    nodes = [1]
    ip_range = "10.1.0.0/16"
    name = "kds_network"
    description = "newer network"
    add_wg_access = true
}

resource "grid_deployment" "d1" {
  node = 1
  network_name = grid_network.net1.name
  ip_range = lookup(grid_network.net1.nodes_ip_range, 1, "")
  disks {
    name = "root"
    size = 10
    description = "root vol"
  }  
  vms {
    name = "vm1"
    # flist = "https://hub.grid.tf/samehabouelsaad.3bot/abouelsaad-grid3_ubuntu20.04-latest.flist"
    flist = "https://hub.grid.tf/omarabdul3ziz.3bot/omarabdul3ziz-ubuntu-20.04-devenv.flist"
    # entrypoint = "/init.sh"
    entrypoint = "/start.sh"
    mounts {
        disk_name = "root"
        mount_point = "/root"
    }    
    cpu = 4
    memory = 1024
    # rootfs_size = 10000
    env_vars = {
      SSH_KEY ="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/9RNGKRjHvViunSOXhBF7EumrWvmqAAVJSrfGdLaVasgaYK6tkTRDzpZNplh3Tk1aowneXnZffygzIIZ82FWQYBo04IBWwFDOsCawjVbuAfcd9ZslYEYB3QnxV6ogQ4rvXnJ7IHgm3E3SZvt2l45WIyFn6ZKuFifK1aXhZkxHIPf31q68R2idJ764EsfqXfaf3q8H3u4G0NjfWmdPm9nwf/RJDZO+KYFLQ9wXeqRn6u/mRx+u7UD+Uo0xgjRQk1m8V+KuLAmqAosFdlAq0pBO8lEBpSebYdvRWxpM0QSdNrYQcMLVRX7IehizyTt+5sYYbp6f11WWcxLx0QDsUZ/J"
    }
    planetary = true
  }

  connection {
    type     = "ssh"
    user     = "root"
    agent    = true
    host     = grid_deployment.d1.vms[0].ygg_ip
  }

  provisioner "remote-exec" {
    inline = [
      "apt update && apt upgrade -y && apt install mc curl git sudo -y",
      # "unminimize",
      "curl https://raw.githubusercontent.com/freeflowuniverse/crystaltools/development/install.sh > /tmp/install.sh", 
      "bash /tmp/install.sh",
      "source /root/env.sh",
      "export PUBSITE=https://github.com/threefoldfoundation/info_threefold_pub/tree/development/wiki_config",
      "cd /root && publishtools flatten",
      # "curl -fsSL https://code-server.dev/install.sh | sh",
      # "sed -i 's/password.*/password: tfrocks/' ~/.config/code-server/config.yaml"
      # "apt-get autoremove && apt-get clean"
    ]
  }
}


output "node1_zmachine1_ip" {
    value = grid_deployment.d1.vms[0].ip
}

output "ygg_ip" {
    value = grid_deployment.d1.vms[0].ygg_ip
}
2 Likes