---
title: "Scale-to-Zero Minecraft server with Terraform and Fly Machines"
description: "This tutorial presents a scale-to-zero Minecraft Java server built with Terraform and Fly Machines. It addresses the cost and resource burden of keeping a multiplayer server running when nobody is playing, while allowing it to restart when a player connects. The configuration provisions a Fly.io app, a Firecracker-based machine using Geoff Bourne’s itzg/minecraft-server Docker image, a 15GB persistent Fly Volume, an IPv4 address, and exposed TCP port 25565. Environment variables enable Autostop with estimated and initial timeouts of 120 seconds, while the machine receives four shared vCPUs and 8GB of RAM and mounts world data at /data. After terraform apply, the machine shuts down after the timeout and automatically starts again when Minecraft reconnects, though any TCP traffic can wake it and incur costs."
---

# Scale-to-Zero Minecraft server with Terraform and Fly Machines

[Fly.io](https://yomu.fyi/company/fly-io) · Sep 14, 2022

**Type:** Tutorial

## Summary

This tutorial presents a scale-to-zero Minecraft Java server built with Terraform and Fly Machines. It addresses the cost and resource burden of keeping a multiplayer server running when nobody is playing, while allowing it to restart when a player connects. The configuration provisions a Fly.io app, a Firecracker-based machine using Geoff Bourne’s itzg/minecraft-server Docker image, a 15GB persistent Fly Volume, an IPv4 address, and exposed TCP port 25565. Environment variables enable Autostop with estimated and initial timeouts of 120 seconds, while the machine receives four shared vCPUs and 8GB of RAM and mounts world data at /data. After terraform apply, the machine shuts down after the timeout and automatically starts again when Minecraft reconnects, though any TCP traffic can wake it and incur costs.

## Context

The guide is motivated by the resource usage and cost of keeping a Minecraft server running continuously, especially when no players are connected. It also notes that Minecraft servers require substantial memory and CPU, and that scale-to-zero can reduce runtime costs.

## Approach / What changed

Terraform provisions a Fly.io app, Fly Machine, persistent Fly Volume, and public IPv4 address. The machine runs the itzg/minecraft-server Docker image with Autostop enabled, exposes TCP port 25565, mounts persistent world data at /data, and uses four shared vCPUs with 8GB of RAM.

## Takeaways

- Autostop is configured through the minecraft-server image with AUTOSTOP\_TIMEOUT\_EST and AUTOSTOP\_TIMEOUT\_INIT both set to 120 seconds.
- The Terraform configuration persists the Minecraft world on a 15GB Fly Volume mounted at /data and exposes the server on TCP port 25565.
- Any TCP traffic can wake the stopped machine, including port scans; destroying the app is presented as the sure way to prevent further charges, including storage costs.

**Tags:** [Fly Machines](https://yomu.fyi/topic/fly-machines), [Terraform](https://yomu.fyi/topic/terraform)

- Source: [Fly.io](https://fly.io/blog/scale-to-zero-minecraft)
- Source URL: https://fly.io/blog/scale-to-zero-minecraft
- Ingested by Yomu: 2026-09-03T01:23:47.654Z

[Read original post](https://fly.io/blog/scale-to-zero-minecraft)
