From 8940c277875007754956490a0c696eb1f6599480 Mon Sep 17 00:00:00 2001 From: DaMandal0rian Date: Tue, 9 Apr 2024 08:41:16 +0300 Subject: [PATCH] create hetzner module for resources --- resources/hetzner/backend.tf | 9 ++++ resources/hetzner/main.tf | 84 ++++++++++++++++++++++++++++++++++ resources/hetzner/outputs.tf | 30 ++++++++++++ resources/hetzner/variables.tf | 76 ++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 resources/hetzner/backend.tf create mode 100644 resources/hetzner/main.tf create mode 100644 resources/hetzner/outputs.tf create mode 100644 resources/hetzner/variables.tf diff --git a/resources/hetzner/backend.tf b/resources/hetzner/backend.tf new file mode 100644 index 00000000..46859de4 --- /dev/null +++ b/resources/hetzner/backend.tf @@ -0,0 +1,9 @@ +terraform { + cloud { + organization = "subspace-sre" + + workspaces { + name = "ephemeral-devnet-hetzner" + } + } +} diff --git a/resources/hetzner/main.tf b/resources/hetzner/main.tf new file mode 100644 index 00000000..22537a6d --- /dev/null +++ b/resources/hetzner/main.tf @@ -0,0 +1,84 @@ +module "network" { + source = "../../templates/terraform/hetzner" + path_to_scripts = "../../templates/scripts" + network_name = var.network_name + + bootstrap-node-config = { + deployment-version = 1 + instance-count = var.instance_count["bootstrap"] + repo-org = "subspace" + node-tag = "bootstrap-node" + additional-node-ips = var.additional_node_ips["bootstrap"] + reserved-only = true + prune = false + genesis-hash = var.genesis_hash + dsn-listen-port = 30533 + node-dsn-port = 30433 + } + + bootstrap-node-evm-config = { + deployment-version = 1 + instance-count = var.instance_count["bootstrap"] + repo-org = "subspace" + node-tag = "bootstrap-node" + additional-node-ips = var.additional_node_ips["bootstrap"] + reserved-only = true + prune = false + genesis-hash = var.genesis_hash + dsn-listen-port = 30533 + node-dsn-port = 30433 + operator-port = 30334 + } + + node-config = { + deployment-version = 1 + instance-count = var.instance_count["node"] + repo-org = "subspace" + node-tag = "subspace-node" + additional-node-ips = var.additional_node_ips["node"] + reserved-only = true + prune = false + node-dsn-port = 30433 + } + + domain-node-config = { + deployment-version = 1 + instance-count = var.instance_count["domain"] + repo-org = "subspace" + node-tag = "subspace-node" + additional-node-ips = var.additional_node_ips["domain"] + domain-prefix = "domain" + reserved-only = true + prune = false + node-dsn-port = 30433 + enable-domains = true + domain-id = var.domain_id + domain-labels = var.domain_labels + } + + farmer-node-config = { + deployment-version = 1 + instance-count = var.instance_count["farmer"] + repo-org = "subspace" + node-tag = "farmer-node" + additional-node-ips = var.additional_node_ips["farmer"] + reserved-only = true + prune = false + plot-size = "10G" + reward-address = var.farmer_reward_address + force-block-production = true + node-dsn-port = 30433 + + } + + tf_token = var.tf_token + private_key_path = var.private_key_path + branch_name = var.branch_name + ssh_user = var.ssh_user + genesis_hash = var.genesis_hash +} + +# External data source to run the shell command and extract the value of the operator bootnode connection parameter +data "external" "operator_peer_multiaddr" { + program = ["bash", "-c", "echo '{\"OPERATOR_MULTI_ADDR\": \"'$(sed -nr 's/^NODE_0_OPERATOR_MULTI_ADDR=(.*)/\\1/p' ./bootstrap_node_evm_keys.txt)'\"}'"] +} diff --git a/resources/hetzner/outputs.tf b/resources/hetzner/outputs.tf new file mode 100644 index 00000000..e3b8f5e6 --- /dev/null +++ b/resources/hetzner/outputs.tf @@ -0,0 +1,30 @@ +output "bootstrap-node-ipv4-addresses" { + value = module.network.bootstrap-node-ipv4-addresses + description = "Bootstrap node IPv4 Addresses" +} + +output "bootstrap-node-evm-ipv4-addresses" { + value = module.network.bootstrap-node-evm-ipv4-addresses + description = "Bootstrap node EVM IPv4 Addresses" +} + +output "node-ipv4-addresses" { + value = module.network.node-ipv4-addresses + description = "subspace node IPv4 Addresses" +} + +output "domain-node-ipv4-addresses" { + value = module.network.domain-node-ipv4-addresses + description = "domain node IPv4 Addresses" +} + + +output "farmer-nodes-ipv4-addresses" { + value = module.network.farmer-node-ipv4-addresses + description = "Farmer node IPv4 Addresses" +} + +# Output the operator_peer_multiaddr value +output "operator_peer_multiaddr" { + value = data.external.operator_peer_multiaddr.result["operator_peer_multiaddr"] +} diff --git a/resources/hetzner/variables.tf b/resources/hetzner/variables.tf new file mode 100644 index 00000000..3228c635 --- /dev/null +++ b/resources/hetzner/variables.tf @@ -0,0 +1,76 @@ +variable "farmer_reward_address" { + description = "Farmer's reward address" + type = string +} + +variable "network_name" { + description = "Network name" + type = string +} + +//todo change this to a map +variable "domain_id" { + description = "Domain ID" + type = list(number) + default = [0] +} + +//todo change this to a map +variable "domain_labels" { + description = "Tag of the domain to run" + type = list(string) + default = ["evm"] +} + +variable "instance_count" { + type = map(number) + default = { + bootstrap = 2 + node = 1 + farmer = 1 + domain = 2 + evm_bootstrap = 1 + } +} + +variable "additional_node_ips" { + type = map(list(string)) + default = { + bootstrap = [""] + node = [""] + farmer = [""] + domain = [""] + evm_bootstrap = [""] + } +} + +variable "ssh_user" { + type = string + default = "root" +} + +variable "private_key_path" { + type = string + default = "~/.ssh/hetzner" +} + +variable "tf_token" { + type = string + sensitive = true +} + +variable "branch_name" { + description = "name of testing branch" + type = string + default = "main" +} + +variable "genesis_hash" { + description = "Genesis hash" + type = string +} + +variable "workspace_name" { + description = "Name of the workspace" + type = string +}