diff --git a/azure/terraform/admin.tf b/azure/terraform/admin.tf --- a/azure/terraform/admin.tf +++ b/azure/terraform/admin.tf @@ -153,7 +153,12 @@ ip_address = azurerm_network_interface.backup-interface[each.key].private_ip_address, facter_subnet = "azure_euwest" facter_deployment = "admin" - disk_setup = {} + disk_setup = { + swaps = [{ + filepath = "/mnt/swapfile" + size = "14336" # GB + }] + } }) destination = var.firstboot_script diff --git a/azure/terraform/templates/firstboot.sh.tpl b/azure/terraform/templates/firstboot.sh.tpl --- a/azure/terraform/templates/firstboot.sh.tpl +++ b/azure/terraform/templates/firstboot.sh.tpl @@ -49,6 +49,18 @@ uuid=$(blkid -o value -s UUID ${disk.base_disk}1) echo "UUID=\"$uuid\" ${disk.mountpoint} ${disk.filesystem} ${disk.mount_options} 0 0" >> /etc/fstab %{ endif } + +%{ for swap in try(disk_setup.swaps, []) } +%{ if try(swap.filepath, "") != "" } +# Create a swapfile +dd if=/dev/zero of=${swap.filepath} bs=1M count=${swap.size} +# enable swap +chmod 600 ${swap.filepath} +mkswap ${swap.filepath} +swapon ${swap.filepath} +# Reference it in /etc/fast so it's persistent across reboots +echo "${swap.filepath} swap swap defaults 0 0" >> /etc/fstab +%{ endif } %{ endfor } %{ if length(try(disk_setup.raids, [])) != 0 }