From 73c63c8ea47620b65dec5e80426fd5b437e6a262 Mon Sep 17 00:00:00 2001 From: Jamil Date: Wed, 19 Mar 2025 12:28:08 -0700 Subject: [PATCH] chore(infra): Use simplified config for swap space (#8488) Turns out cloud-init has native support for configuring swapfiles, so we use that here and make it configurable. The `environments` submodule will be updated to inject the current value into here. --- .github/workflows/_terraform.yml | 3 ++- terraform/environments | 2 +- terraform/modules/google-cloud/apps/elixir/main.tf | 4 +++- .../google-cloud/apps/elixir/templates/cloud-init.yaml | 10 +++++----- .../modules/google-cloud/apps/elixir/variables.tf | 6 ++++++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/_terraform.yml b/.github/workflows/_terraform.yml index d889c6016..15fbdb062 100644 --- a/.github/workflows/_terraform.yml +++ b/.github/workflows/_terraform.yml @@ -29,7 +29,8 @@ jobs: sudo apt-get update sudo apt-get install -y cloud-init sudo cloud-init schema --config-file terraform/modules/google-cloud/apps/relay/templates/cloud-init.yaml - sudo cloud-init schema --config-file terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml + # This doesn't work if the file contains interpolated variables + # sudo cloud-init schema --config-file terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml sudo cloud-init schema --config-file terraform/modules/google-cloud/apps/gateway-region-instance-group/templates/cloud-init.yaml - name: Check Formatting working-directory: terraform diff --git a/terraform/environments b/terraform/environments index 35ca3f75d..a4915959b 160000 --- a/terraform/environments +++ b/terraform/environments @@ -1 +1 @@ -Subproject commit 35ca3f75df8c8b861fab021bc968345a5a291d49 +Subproject commit a4915959bcb868c4babc69eb6b638ca969a2d993 diff --git a/terraform/modules/google-cloud/apps/elixir/main.tf b/terraform/modules/google-cloud/apps/elixir/main.tf index 6e95094aa..0a8bac68e 100644 --- a/terraform/modules/google-cloud/apps/elixir/main.tf +++ b/terraform/modules/google-cloud/apps/elixir/main.tf @@ -198,7 +198,9 @@ resource "google_compute_instance_template" "application" { } }) - user-data = templatefile("${path.module}/templates/cloud-init.yaml", {}) + user-data = templatefile("${path.module}/templates/cloud-init.yaml", { + swap_size_gb = var.compute_swap_size_gb + }) google-logging-enabled = "true" google-logging-use-fluentbit = "true" diff --git a/terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml b/terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml index 55d282df0..ba51c71d4 100644 --- a/terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml +++ b/terraform/modules/google-cloud/apps/elixir/templates/cloud-init.yaml @@ -98,8 +98,8 @@ runcmd: - sudo ip6tables-restore < /etc/iptables/rules.v6 - systemctl daemon-reload - systemctl start otel-collector.service - # Enable swapspace to minimize OOM kills - - fallocate -l 1G /var/swapfile - - chmod 600 /var/swapfile - - mkswap /var/swapfile - - swapon /var/swapfile + +swap: + filename: /swapfile + size: ${swap_size_gb}G + maxsize: ${swap_size_gb}G diff --git a/terraform/modules/google-cloud/apps/elixir/variables.tf b/terraform/modules/google-cloud/apps/elixir/variables.tf index ae2ae3527..5410ba1be 100644 --- a/terraform/modules/google-cloud/apps/elixir/variables.tf +++ b/terraform/modules/google-cloud/apps/elixir/variables.tf @@ -29,6 +29,12 @@ variable "compute_boot_disk_type" { description = "Type of the boot disk." } +variable "compute_swap_size_gb" { + type = number + default = 0 + description = "Size of the swap disk in GB." +} + ################################################################################ ## VPC ################################################################################