Skip to content

Commit

Permalink
[tf/gcp] option to separate k8s workloads from TF state
Browse files Browse the repository at this point in the history
  • Loading branch information
rustielin committed Dec 7, 2022
1 parent fca7c58 commit 80251e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion terraform/aptos-node/aws/kubernetes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ locals {

# 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
"imageTag" = var.image_tag
"chain.era" = var.era
}
}
Expand Down
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
}

0 comments on commit 80251e5

Please sign in to comment.