Skip to content

Commit

Permalink
Merge pull request #81 from kaleido-io/remote_peering
Browse files Browse the repository at this point in the history
Remote peering
  • Loading branch information
calbritt authored Oct 11, 2024
2 parents 9ed8267 + 9b7cb2f commit 8844ec9
Show file tree
Hide file tree
Showing 17 changed files with 1,508 additions and 41 deletions.
4 changes: 4 additions & 0 deletions examples/platform_stack/terraform.tfvars.local_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kaleido_platform_api = "https://myaccount.kaleido.dev"
kaleido_platform_username = "key1"
kaleido_platform_password = "ac8255da-9ddf-4be4-92ad-daa957196e7a8e0328af-10b8-47f0-96ce-ebc042da7b89"
environment_name = "env_alex"
4 changes: 4 additions & 0 deletions examples/platform_stack_two_env_besu_network/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.terraform*
terraform.d
terraform.tfstate*
terraform.tfvars
240 changes: 240 additions & 0 deletions examples/platform_stack_two_env_besu_network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
terraform {
required_providers {
kaleido = {
source = "kaleido-io/kaleido"
version = "1.1.0-rc.4"
configuration_aliases = [ kaleido.originator, kaleido.secondary ]
}
}
}

provider "kaleido" {
alias = "originator"
platform_api = var.originator_api_url
platform_username = var.originator_api_key_name
platform_password = var.originator_api_key_value
}

provider "kaleido" {
alias = "secondary"
platform_api = var.secondary_api_url
platform_username = var.secondary_api_key_name
platform_password = var.secondary_api_key_value
}

// Environment 1 - the originator of the network

resource "kaleido_platform_environment" "env_og" {
provider = kaleido.originator
name = var.originator_name
}

resource "kaleido_platform_network" "net_og" {
provider = kaleido.originator
type = "Besu"
name = var.originator_name
environment = kaleido_platform_environment.env_og.id
init_mode = "automated"

config_json = jsonencode({
chainID = 12345
bootstrapOptions = {
qbft = {
blockperiodseconds = 5
}
eipBlockConfig = {
shanghaiTime = 0
}
initialBalances = {
"0x12F62772C4652280d06E64CfBC9033d409559aD4" = "0x111111111111",
}
blockConfigFlags = {
zeroBaseFee = true
}
}
})
}


resource "kaleido_platform_runtime" "bnr_signer_net_og" {
provider = kaleido.originator
type = "BesuNode"
name = "${var.originator_name}_signer${count.index+1}"
environment = kaleido_platform_environment.env_og.id
config_json = jsonencode({})
count = var.originator_signer_count
}

resource "kaleido_platform_service" "bns_signer_net_og" {
provider = kaleido.originator
type = "BesuNode"
name = "${var.originator_name}_signer${count.index+1}"
environment = kaleido_platform_environment.env_og.id
runtime = kaleido_platform_runtime.bnr_signer_net_og[count.index].id
config_json = jsonencode({
network = {
id = kaleido_platform_network.net_og.id
}
signer = true
})
count = var.originator_signer_count
}

resource "kaleido_platform_runtime" "bnr_peer_net_og" {
provider = kaleido.originator
type = "BesuNode"
name = "${var.originator_name}_peer${count.index+1}"
environment = kaleido_platform_environment.env_og.id
zone = var.originator_peer_network_dz
config_json = jsonencode({})
count = var.originator_peer_count
}

resource "kaleido_platform_service" "bns_peer_net_og" {
provider = kaleido.originator
type = "BesuNode"
name = "${var.originator_name}_peer${count.index+1}"
environment = kaleido_platform_environment.env_og.id
runtime = kaleido_platform_runtime.bnr_peer_net_og[count.index].id
config_json = jsonencode({
network = {
id = kaleido_platform_network.net_og.id
}
signer = false
})
count = var.originator_peer_count
}

resource "kaleido_platform_runtime" "gwr_net_og" {
provider = kaleido.originator
type = "EVMGateway"
name = "${var.originator_name}_gateway"
environment = kaleido_platform_environment.env_og.id
config_json = jsonencode({})
count = var.originator_gateway_count
}


resource "kaleido_platform_service" "gws_net_og" {
provider = kaleido.originator
type = "EVMGateway"
name = "${var.originator_name}_gateway"
environment = kaleido_platform_environment.env_og.id
runtime = kaleido_platform_runtime.gwr_net_og[count.index].id
config_json = jsonencode({
network = {
id = kaleido_platform_network.net_og.id
}
})
count = var.originator_gateway_count
}

data "kaleido_platform_network_bootstrap_data" "net_og_bootstrap" {
provider = kaleido.originator
environment = kaleido_platform_environment.env_og.id
network = kaleido_platform_network.net_og.id
depends_on = [
kaleido_platform_service.bns_signer_net_og,
kaleido_platform_network.net_og
]
}



// Environment 2 - another member of the network

resource "kaleido_platform_environment" "env_sec" {
provider = kaleido.secondary
name = var.secondary_name
}

resource "kaleido_platform_network" "net_sec" {
provider = kaleido.secondary
type = "Besu"
name = var.secondary_name
environment = kaleido_platform_environment.env_sec.id
init_mode = "manual"
file_sets = data.kaleido_platform_network_bootstrap_data.net_og_bootstrap.bootstrap_files != null ? {
init = data.kaleido_platform_network_bootstrap_data.net_og_bootstrap.bootstrap_files
} : {}
init_files = data.kaleido_platform_network_bootstrap_data.net_og_bootstrap.bootstrap_files != null ? "init" : null
config_json = jsonencode({})
depends_on = [kaleido_platform_network.net_og, kaleido_platform_service.bns_signer_net_og, data.kaleido_platform_network_bootstrap_data.net_og_bootstrap]
}

resource "kaleido_platform_runtime" "bnr_peer_net_sec" {
provider = kaleido.secondary
type = "BesuNode"
name = "${var.secondary_name}_peer${count.index+1}"
environment = kaleido_platform_environment.env_sec.id
zone = var.secondary_peer_network_dz
config_json = jsonencode({})
count = var.secondary_peer_count
depends_on = [kaleido_platform_network.net_sec]
}

resource "kaleido_platform_service" "bns_peer_net_sec" {
provider = kaleido.secondary
type = "BesuNode"
name = "${var.secondary_name}_peer${count.index+1}"
environment = kaleido_platform_environment.env_sec.id
runtime = kaleido_platform_runtime.bnr_peer_net_sec[count.index].id
config_json = jsonencode({
network = {
id = kaleido_platform_network.net_sec.id
}
signer = false
})
count = var.secondary_peer_count
}

resource "kaleido_platform_runtime" "gwr_net_sec" {
provider = kaleido.secondary
type = "EVMGateway"
name = "${var.originator_name}_gateway"
environment = kaleido_platform_environment.env_sec.id
config_json = jsonencode({})
depends_on = [kaleido_platform_network.net_sec]
count = var.secondary_gateway_count
}

resource "kaleido_platform_service" "gws_net_sec" {
provider = kaleido.secondary
type = "EVMGateway"
name = "${var.originator_name}_gateway"
environment = kaleido_platform_environment.env_sec.id
runtime = kaleido_platform_runtime.gwr_net_sec[count.index].id
config_json = jsonencode({
network = {
id = kaleido_platform_network.net_sec.id
}
})
count = var.secondary_gateway_count
}


// Authenticators
resource "kaleido_platform_authenticator" "net_sec_authenticator" {
provider = kaleido.secondary
type = "Permitted"
name = "${var.secondary_name}_auth"
environment = kaleido_platform_environment.env_sec.id
network = kaleido_platform_network.net_sec.id
zone = var.secondary_peer_network_dz
conn = var.secondary_peer_network_connection
permitted_json = jsonencode({ peers = [ for peer in resource.kaleido_platform_service.bns_peer_net_og : jsondecode(peer.connectivity_json) ] })
depends_on = [kaleido_platform_network.net_sec, kaleido_platform_service.bns_peer_net_og]
}


resource "kaleido_platform_authenticator" "net_og_authenticator" {
provider = kaleido.originator
type = "Permitted"
name = "${var.originator_name}_auth"
environment = kaleido_platform_environment.env_og.id
network = kaleido_platform_network.net_og.id
zone = var.originator_peer_network_dz
conn = var.originator_peer_network_connection
permitted_json = jsonencode({ peers = [ for peer in resource.kaleido_platform_service.bns_peer_net_sec : jsondecode(peer.connectivity_json) ] })
depends_on = [kaleido_platform_network.net_og, kaleido_platform_service.bns_peer_net_sec]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kaleido_platform_api_baseurl = "kaleido.dev"

originator_account_name = "myaccount"
originator_api_key_name = "key1"
originator_api_key_value = "1dbf8a3a-51c0-4e5e-a36a-50c58535db1b60cb9dc4-691c-4243-b88e-221a890cc511"

secondary_account_name = "other"
secondary_api_key_name = "key1"
secondary_api_key_value = "fc07c759-dace-445e-9a06-8c21cca4e7080cd9e28d-32f6-4c49-96b6-839d009fb1fb"

originator_name = "besu_originator"
originator_signer_count = 2
originator_peer_count = 1
originator_peer_network_dz = "local-external-zone-1"
originator_peer_network_connection = "local"

secondary_name = "besu_secondary"
secondary_peer_count = 2
secondary_peer_network_dz = "local-external-zone-1"
secondary_peer_network_connection = "local"
81 changes: 81 additions & 0 deletions examples/platform_stack_two_env_besu_network/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

variable "originator_api_url" {
type = string
}

variable "originator_api_key_name" {
type = string
}

variable "originator_api_key_value" {
type = string
}

variable "secondary_api_url" {
type = string
}

variable "secondary_api_key_name" {
type = string
}

variable "secondary_api_key_value" {
type = string
}

variable "originator_name" {
type = string
}

variable "secondary_name" {
type = string
}

variable "originator_signer_count" {
type = number
default = 1
}

variable "originator_peer_count" {
type = number
default = 1
}

variable "secondary_peer_count" {
type = number
default = 1
}

variable "originator_peer_network_dz" {
type = string
}

variable "originator_peer_network_connection" {
type = string
}

variable "secondary_peer_network_dz" {
type = string
}

variable "secondary_peer_network_connection" {
type = string
}

variable "originator_gateway_count" {
type = number
default = 1
validation {
condition = contains([0, 1], var.originator_gateway_count)
error_message = "Valid values for originator_gateway_count are (0, 1)"
}
}

variable "secondary_gateway_count" {
type = number
default = 1
validation {
condition = contains([0, 1], var.secondary_gateway_count)
error_message = "Valid values for secondary_gateway_count are (0, 1)"
}
}
Loading

0 comments on commit 8844ec9

Please sign in to comment.