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.
This commit is contained in:
Jamil
2025-03-19 12:28:08 -07:00
committed by GitHub
parent 3313e7377e
commit 73c63c8ea4
5 changed files with 17 additions and 8 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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
################################################################################