Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

feat: add infra as code for digital ocean instance. #55

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,30 @@ dist
.env.development
.env.test

.DS_Store
# Ignore all .tfvars files
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as password, secret keys
*.tfvars

# Ignore override files as they are usually used for local dev overrides.
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore CLI configuration files
.terraformrc
terraform.rc


id_rsa.pub
.DS_Store
26 changes: 26 additions & 0 deletions infra/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.do_token
}

resource "digitalocean_ssh_key" "default" {
name = var.ssh_key_name
public_key = file(var.ssh_public_key_file)
}

resource "digitalocean_droplet" "subtensor" {
image = "ubuntu-20-04-x64"
name = "example-droplet"
region = "nyc1"
size = "s-1vcpu-1gb" # Smallest droplet size
ssh_keys = [digitalocean_ssh_key.default.id]

user_data = <<-EOF
#!/bin/bash
# Update apt
sudo apt update

# Install additional required libraries and tools
sudo apt install --assume-yes make build-essential git clang curl libssl-dev llvm libudev-dev protobuf-compiler

# Clone the subtensor repository
git clone https://github.com/opentensor/subtensor.git
# TODO: add starting the subnet here.
EOF
}

output "ssh_command" {
value = "ssh <your_username>@${digitalocean_droplet.subtensor.ipv4_address}"
}
2 changes: 2 additions & 0 deletions infra/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
do_token = "your-digitalocean-api-token"
ssh_public_key_file = "path/to/your/ssh/public/key/file"
11 changes: 11 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "do_token" {
description = "DigitalOcean API token"
}

variable "ssh_public_key_file" {
description = "Path to the SSH public key file"
}

variable "ssh_key_name" {
description = "The name of the SSH key on DigitalOcean"
}
Loading