Terraform modules to provision a headless Factorio server in AWS, with save game backups to S3.
- Terraform version 0.13.x
- Amazon AWS account and access keys
-
Put AWS credentials in
~/.aws/credentials
(aws_access_key_id
andaws_secret_access_key
) -
Configure and create stateful infrastructure:
cd state/ terraform init && terraform apply terraform output # Take note of bucket name in output bucket_name = factorio-20190602222917314000000001
-
Configure stateless infrastructure:
cd instance/ terraform init # Add correct bucket_name from above vim terraform.tfvars
-
Configure Factorio server (see Setting up a Linux Factorio server):
vim conf/server-settings.json
Create stateless infrastructure:
cd instance/
terraform apply
terraform output
# Public IP of the game server
ip = 3.121.142.76
The game server is automatically started and the most recent save games from S3 are restored onto the instance.
Destroy infrastructure after use:
cd instance/
terraform destroy
This will automatically backup the save games to the specified S3 bucket.
state/
contains the Terraform module for the stateful server infrastructure. This includes the S3 bucket holding game state inbetween games, i.e. while the server instance does not exist.instance/
contains the Terraform module for the stateless server infrastructure. This includes the EC2 instance that runs the game server.
Several systemd services are provisioned to the server instance:
factorio-headless.service
: Service to start/stop the headless game server.factorio-restore.service
: One shot service that restores save games from S3.factorio-backup.service
: One shot service that backs up save games to S3.
You can use the connect.sh
script to connect to the game server via SSH.
Currently there is no support for creating a fresh game, just for loading existing
save games. The headless Factorio server expects the --create FILE
argument to
create a game. The workaround is to create a game locally, export the save game,
and use that.
This provisioning code populates --start-server FILE
(to load a named save game) or
-start-server-load-latest
(to load the latest save game), depending on whether
the factorio_save_game
variable is set.