Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform k8s separation #5755

Merged
merged 2 commits into from
Dec 7, 2022
Merged
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
22 changes: 22 additions & 0 deletions terraform/aptos-node-testnet/addons.tf
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,27 @@ resource "helm_release" "external-dns" {
]
}

locals {
# these values are the most likely to be changed by the user and may be managed by terraform to trigger re-deployment
testnet_addons_helm_values_managed = {
"imageTag" = var.image_tag
"genesis.era" = var.era
}
}

resource "helm_release" "testnet-addons" {
count = var.enable_forge ? 0 : 1
name = "testnet-addons"
chart = local.testnet_addons_helm_chart_path
max_history = 5
wait = false

lifecycle {
ignore_changes = [
values,
]
}

values = [
jsonencode({
imageTag = var.image_tag
Expand Down Expand Up @@ -260,6 +274,14 @@ resource "helm_release" "testnet-addons" {
jsonencode(var.testnet_addons_helm_values)
]

dynamic "set" {
for_each = var.manage_via_tf ? local.testnet_addons_helm_values_managed : {}
content {
name = set.key
value = set.value
}
}

# inspired by https://stackoverflow.com/a/66501021 to trigger redeployment whenever any of the charts file contents change.
set {
name = "chart_sha1"
Expand Down
24 changes: 24 additions & 0 deletions terraform/aptos-node-testnet/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ locals {
module "validator" {
source = "../aptos-node/aws"

manage_via_tf = var.manage_via_tf

maximize_single_az_capacity = var.maximize_single_az_capacity

region = var.region
Expand Down Expand Up @@ -92,14 +94,27 @@ provider "kubernetes" {

locals {
genesis_helm_chart_path = "${path.module}/../helm/genesis"

# these values are the most likely to be changed by the user and may be managed by terraform to trigger re-deployment
genesis_helm_values_managed = {
"imageTag" = var.image_tag
"chain.era" = var.era
}
}


resource "helm_release" "genesis" {
name = "genesis"
chart = local.genesis_helm_chart_path
max_history = 5
wait = false

lifecycle {
ignore_changes = [
values,
]
}

values = [
jsonencode({
chain = {
Expand All @@ -124,6 +139,15 @@ resource "helm_release" "genesis" {
}),
jsonencode(var.genesis_helm_values)
]

dynamic "set" {
for_each = var.manage_via_tf ? local.genesis_helm_values_managed : {}
content {
name = set.key
value = set.value
}
}

# inspired by https://stackoverflow.com/a/66501021 to trigger redeployment whenever any of the charts file contents change.
set {
name = "chart_sha1"
Expand Down
5 changes: 5 additions & 0 deletions terraform/aptos-node-testnet/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,8 @@ variable "fullnode_storage_class" {
error_message = "Supported storage classes are gp3, io1, io2"
}
}

variable "manage_via_tf" {
description = "Whether to manage the aptos-node k8s workload via Terraform"
default = true
}
20 changes: 20 additions & 0 deletions terraform/aptos-node/aws/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ locals {

# override the helm release name if an override exists, otherwise adopt the workspace name
helm_release_name = var.helm_release_name_override != "" ? var.helm_release_name_override : local.workspace_name

# these values are the most likely to be changed by the user and may be managed by terraform to trigger re-deployment
helm_values_managed = {
"imageTag" = var.image_tag
"chain.era" = var.era
}
}

resource "helm_release" "validator" {
Expand All @@ -178,12 +184,26 @@ resource "helm_release" "validator" {
max_history = 5
wait = false

lifecycle {
ignore_changes = [
values,
]
}

values = [
local.helm_values,
var.helm_values_file != "" ? file(var.helm_values_file) : "{}",
jsonencode(var.helm_values),
]

dynamic "set" {
for_each = var.manage_via_tf ? local.helm_values_managed : {}
content {
name = set.key
value = set.value
}
}

# inspired by https://stackoverflow.com/a/66501021 to trigger redeployment whenever any of the charts file contents change.
set {
name = "chart_sha1"
Expand Down
5 changes: 5 additions & 0 deletions terraform/aptos-node/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,8 @@ variable "fullnode_storage_class" {
error_message = "Supported storage classes are gp3, io1, io2"
}
}

variable "manage_via_tf" {
description = "Whether to manage the aptos-node k8s workload via Terraform"
default = true
}
20 changes: 20 additions & 0 deletions terraform/aptos-node/gcp/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ locals {
monitoring_helm_chart_path = "${path.module}/../../helm/monitoring"
logger_helm_chart_path = "${path.module}/../../helm/logger"
aptos_node_helm_chart_path = var.helm_chart != "" ? var.helm_chart : "${path.module}/../../helm/aptos-node"

# these values are the most likely to be changed by the user and may be managed by terraform to trigger re-deployment
helm_values_managed = {
"imageTag" = var.image_tag
"chain.era" = var.era
}
}

resource "helm_release" "validator" {
Expand All @@ -36,6 +42,12 @@ resource "helm_release" "validator" {
max_history = 5
wait = false

lifecycle {
ignore_changes = [
values,
]
}

values = [
jsonencode({
imageTag = var.image_tag
Expand Down Expand Up @@ -76,6 +88,14 @@ resource "helm_release" "validator" {
jsonencode(var.helm_values),
]

dynamic "set" {
for_each = var.manage_via_tf ? local.helm_values_managed : {}
content {
name = set.key
value = set.value
}
}

# inspired by https://stackoverflow.com/a/66501021 to trigger redeployment whenever any of the charts file contents change.
set {
name = "chart_sha1"
Expand Down
5 changes: 5 additions & 0 deletions terraform/aptos-node/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,8 @@ variable "node_exporter_helm_values" {
type = any
default = {}
}

variable "manage_via_tf" {
description = "Whether to manage the aptos-node k8s workload via Terraform"
default = true
}