Skip to content

Commit

Permalink
feat: gcp cloud provider (#53)
Browse files Browse the repository at this point in the history
Support GCP as a cloud provider.

To ensure backwards compatibility, the default is configured for AWS.

Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Nov 19, 2024
1 parent 9f24ebf commit 533cd7f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
10 changes: 6 additions & 4 deletions bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module "node_v1_proxy_blue" {
resources = var.proxy_resources
instances_namespace = var.proxy_blue_instances_namespace
healthcheck_port = var.proxy_blue_healthcheck_port
cloud_provider = var.cloud_provider
environment = "blue"
name = "proxy-blue"
}
Expand All @@ -44,6 +45,7 @@ module "node_v1_proxy_green" {
resources = var.proxy_resources
instances_namespace = var.proxy_green_instances_namespace
healthcheck_port = var.proxy_green_healthcheck_port
cloud_provider = var.cloud_provider
environment = "green"
name = "proxy-green"
}
Expand Down Expand Up @@ -84,7 +86,6 @@ module "instances" {
is_relay = coalesce(each.value.is_relay, false)
}


module "custom_configs" {
depends_on = [kubernetes_namespace.namespace]
source = "./configs"
Expand All @@ -111,7 +112,8 @@ module "services" {
}

module "node_relay" {
depends_on = [kubernetes_namespace.namespace]
source = "./relay"
namespace = var.namespace
depends_on = [kubernetes_namespace.namespace]
source = "./relay"
namespace = var.namespace
cloud_provider = var.cloud_provider
}
4 changes: 4 additions & 0 deletions bootstrap/proxy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ variable "dns_zone" {
variable "healthcheck_port" {
type = number
}

variable "cloud_provider" {
type = string
}
35 changes: 34 additions & 1 deletion bootstrap/proxy/service.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "kubernetes_service_v1" "proxy_service" {
resource "kubernetes_service_v1" "proxy_service_aws" {
for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "aws"])
metadata {
name = local.name
namespace = var.namespace
Expand Down Expand Up @@ -33,3 +34,35 @@ resource "kubernetes_service_v1" "proxy_service" {
type = "LoadBalancer"
}
}

resource "kubernetes_service_v1" "proxy_service_gcp" {
for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "gcp"])
metadata {
name = local.name
namespace = var.namespace
annotations = {
"cloud.google.com/l4-rbs" : "enabled"
}
}

spec {
external_traffic_policy = "Local"
selector = local.proxy_labels

port {
name = "proxy"
port = 9443
target_port = local.proxy_port
protocol = "TCP"
}

port {
name = "health"
port = 80
target_port = local.prometheus_port
protocol = "TCP"
}

type = "LoadBalancer"
}
}
49 changes: 48 additions & 1 deletion bootstrap/relay/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ variable "namespace" {
description = "the namespace where the resources will be created"
}

resource "kubernetes_service_v1" "node-relay-n2n" {
variable "cloud_provider" {
type = string
default = "aws"
}

resource "kubernetes_service_v1" "node-relay-n2n-aws" {
for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "aws"])
metadata {
name = "node-relay-n2n"
namespace = var.namespace
Expand Down Expand Up @@ -43,3 +49,44 @@ resource "kubernetes_service_v1" "node-relay-n2n" {
}
}
}

resource "kubernetes_service_v1" "node-relay-n2n-gcp" {
for_each = toset([for n in toset(["loadbalancer"]) : n if var.cloud_provider == "gcp"])
metadata {
name = "node-relay-n2n"
namespace = var.namespace
annotations = {
"cloud.google.com/l4-rbs" : "enabled"
}
}

spec {
type = "LoadBalancer"
external_traffic_policy = "Local"

selector = {
"role" = "node"
}

port {
name = "mainnet"
protocol = "TCP"
port = 3000
target_port = "n2n-mainnet"
}

port {
name = "preprod"
protocol = "TCP"
port = 3001
target_port = "n2n-preprod"
}

port {
name = "preview"
protocol = "TCP"
port = 3002
target_port = "n2n-preview"
}
}
}
5 changes: 5 additions & 0 deletions bootstrap/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "cloud_provider" {
type = string
default = "aws"
}

variable "namespace" {
type = string
}
Expand Down

0 comments on commit 533cd7f

Please sign in to comment.