This repository contains Terraform configurations to deploy a fully functional Minecraft server on Google Cloud Platform (GCP).
The infrastructure is designed to be cost-effective and flexible:
- Persistent Storage: Your world data is stored on a separate Persistent Disk. You can destroy the server VM to save costs when not playing, without losing your world.
- Dockerized: Uses the popular itzg/minecraft-server Docker image.
- Configurable: Easily change Minecraft version, RAM, server type (Vanilla, Spigot, Paper, etc.) via Terraform variables.
The project is split into two Terraform states:
01_persistent: Creates the Persistent Disk (PD) and a static IP (optional, depending on config). This state is meant to be kept alive.02_server: Creates the Compute Engine VM, firewall rules, and attaches the existing disk. This state can be destroyed and recreated at will.
- A Google Cloud Platform (GCP) Project.
- Terraform installed.
- Google Cloud SDK (gcloud) installed.
Authenticate Terraform with your GCP account:
gcloud auth application-default loginBefore running Terraform, you must configure where the state file is stored.
- Open
terraform/01_persistent/provider.tfandterraform/02_server/provider.tf. - Change the
bucketvalue to a unique name (e.g.,yourname-minecraft-tfstate). Bucket names must be globally unique across all of Google Cloud.
-
Copy the example variable files and create symbolic links:
mv terraform/terraform.tfvars.example terraform/terraform.tfvars ln -s ../terraform.tfvars terraform/01_persistent/terraform.tfvars ln -s ../terraform.tfvars terraform/02_server/terraform.tfvars
-
Edit
terraform.tfvarsin the rootterraformdirectory with your specific values (Project ID, Region, etc.).
Key Variables:
| Variable | Description | Default |
|---|---|---|
project_id |
Required. Your GCP Project ID. | - |
region / zone |
GCP Region and Zone. | europe-west9 / europe-west9-b |
machine_type |
VM size (e.g., e2-medium, e2-standard-2). |
e2-medium |
minecraft_disk_size |
Size of the Persistent Disk (in GB). | 20 |
minecraft_image |
Docker image to use for the server. | itzg/minecraft-server:java25 |
minecraft_version |
Minecraft version (e.g., 1.20.4, LATEST). |
LATEST |
minecraft_type |
Server type (VANILLA, PAPER, FORGE...). |
VANILLA |
minecraft_memory |
RAM allocated to Java (e.g., 2G, 4G). |
2G |
minecraft_difficulty |
Game difficulty (peaceful, easy, etc.). |
normal |
minecraft_motd |
Message of the Day. | Minecraft Server on GCP |
minecraft_icon |
URL to server icon. | https://www.gstatic.com/cgc/super_cloud.png |
minecraft_ops |
List of OP players (comma-separated). | "" |
modrinth_projects |
List of Modrinth projects (slugs/IDs) to install | "" |
voice_chat_port |
UDP port for Simple Voice Chat plugin | 24454 |
minecraft_max_players |
Maximum number of players allowed. | 10 |
minecraft_enable_rcon |
Enable RCON for remote server management. | true |
use_spot_instance |
Use Spot VM (cheaper but can be stopped by GCP) | false |
enable_static_ip |
Enable static IP address creation and usage | true |
enable_scheduler |
Enable automatic start/stop scheduler | false |
scheduler_start_time |
Cron schedule for starting the server | 0 8 * * * (8 AM) |
scheduler_stop_time |
Cron schedule for stopping the server | 0 23 * * * (11 PM) |
scheduler_timezone |
Timezone for the scheduler | Europe/Paris |
First, create the disk that will hold your data.
cd terraform/01_persistent
terraform init
terraform applyReview the plan and type
yesto confirm.
Once the disk is created, deploy the server VM.
cd ../02_server
terraform init
terraform applyReview the plan and type
yesto confirm.
After the deployment of 02_server is complete, Terraform will output the public IP address of your server.
Copy this IP into your Minecraft client to connect.
To stop paying for the Compute Engine VM when you are not playing:
cd terraform/02_server
terraform destroyNote: This only destroys the VM. Your data (world, inventory, etc.) is safe on the Persistent Disk created in step 3.
To restart the server (e.g., to update the Minecraft version after changing minecraft_version variable):
- Run
terraform destroyin02_server. - Run
terraform applyin02_server.
If you want to delete everything permanently (including your world data):
-
Destroy the server:
cd terraform/02_server terraform destroy -
Destroy the disk:
cd ../01_persistent terraform destroy
You can back up your Minecraft world data by running the provided backup script. This script creates a compressed archive of your world data and saves it locally.
cd scripts
./backup_world.shTo use the script, ensure you have
gcloudinstalled and authenticated, and that you have the necessary permissions to access the Persistent Disk.
- Permissions Error: If you see an error about
iam.serviceAccountUser, ensure your current user or the service account running Terraform has theService Account Userrole. - Disk not found: Ensure you have successfully applied
01_persistentbefore trying to apply02_server.
This project is licensed under the MIT License - see the LICENSE file for details.
Romain Lancelot - GitHub