Skip to content

Commit

Permalink
[tf][do] fullnode tf on digital ocean
Browse files Browse the repository at this point in the history
  • Loading branch information
cs authored and aptos-bot committed May 4, 2022
1 parent fcf8f8c commit b28a4f1
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 0 deletions.
3 changes: 3 additions & 0 deletions terraform/fullnode/digital_ocean/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tfstate
*.tfstate.backup
*.yml
82 changes: 82 additions & 0 deletions terraform/fullnode/digital_ocean/.terraform.lock.hcl

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

12 changes: 12 additions & 0 deletions terraform/fullnode/digital_ocean/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "digitalocean_kubernetes_cluster" "aptos" {
name = "aptos-${terraform.workspace}"
region = var.region
version = "1.22.8-do.1"

node_pool {
name = "fullnodes"
size = var.machine_type
node_count = var.num_fullnodes
tags = ["fullnodes"]
}
}
59 changes: 59 additions & 0 deletions terraform/fullnode/digital_ocean/kubernetes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
provider "kubernetes" {
host = "${digitalocean_kubernetes_cluster.aptos.endpoint}"
cluster_ca_certificate = base64decode(digitalocean_kubernetes_cluster.aptos.kube_config[0].cluster_ca_certificate)
token = digitalocean_kubernetes_cluster.aptos.kube_config[0].token
}

resource "kubernetes_namespace" "aptos" {
metadata {
name = var.k8s_namespace
}
}

provider "helm" {
kubernetes {
host = "${digitalocean_kubernetes_cluster.aptos.endpoint}"
cluster_ca_certificate = base64decode(digitalocean_kubernetes_cluster.aptos.kube_config[0].cluster_ca_certificate)
token = digitalocean_kubernetes_cluster.aptos.kube_config[0].token
}
}

resource "helm_release" "fullnode" {
count = var.num_fullnodes
name = "${terraform.workspace}${count.index}"
chart = "${path.module}/../../helm/fullnode"
max_history = 100
wait = false
namespace = var.k8s_namespace
create_namespace = true

values = [
jsonencode({
chain = {
era = var.era
}
image = {
tag = var.image_tag
}
nodeSelector = {
"doks.digitalocean.com/node-pool" = digitalocean_kubernetes_cluster.aptos.node_pool[0].name
}
storageClass = {
class = "do-block-storage"
}
service = {
type = "LoadBalancer"
}
storage = {
size = "100Gi"
}
}),
jsonencode(var.fullnode_helm_values),
jsonencode(var.fullnode_helm_values_list == {} ? {} : var.fullnode_helm_values_list[count.index]),
]

set {
name = "timestamp"
value = var.helm_force_update ? timestamp() : ""
}
}
14 changes: 14 additions & 0 deletions terraform/fullnode/digital_ocean/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "local" {}

provider "digitalocean" {
token = var.do_token
}
67 changes: 67 additions & 0 deletions terraform/fullnode/digital_ocean/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
variable "helm_values" {
description = "Map of values to pass to Helm"
type = any
default = {}
}

variable "fullnode_helm_values" {
description = "Map of values to pass to public fullnode Helm"
type = any
default = {}
}

variable "do_token" {
type = string
description = "Digital Notion API token"
}

variable "region" {
description = "Digital Ocean region of nodes"
type = string
}

variable "fullnode_helm_values_list" {
description = "List of values to pass to public fullnode, for setting different value per node. length(fullnode_helm_values_list) must equal var.num_fullnodes"
type = any
default = {}
}

variable "helm_force_update" {
description = "Force Terraform to update the Helm deployment"
default = false
}

variable "k8s_namespace" {
default = "aptos"
description = "Kubernetes namespace that the fullnode will be deployed into"
}

variable "k8s_api_sources" {
description = "List of CIDR subnets which can access the Kubernetes API endpoint"
default = ["0.0.0.0/0"]
}

variable "num_fullnodes" {
default = 1
description = "Number of fullnodes"
}

variable "image_tag" {
default = "devnet"
description = "Docker image tag to use for the fullnode"
}

variable "era" {
description = "Chain era, used to start a clean chain"
default = 1
}

variable "chain_id" {
description = "aptos chain ID"
default = "DEVNET"
}

variable "machine_type" {
description = "Machine type for running fullnode"
default = "s-4vcpu-8gb"
}

0 comments on commit b28a4f1

Please sign in to comment.