Skip to content

Harry-Moore-dev/terraform-aws-minecraft-server-module

Repository files navigation

terraform-aws-minecraft-server-module

Terraform module to deploy a Minecraft server to AWS. This module is designed to be stateless and ephemeral, creating and destroying a new server should be possible without affecting the saved Minecraft worlds, this is acheived by storing the saved data in s3 externally to this module on a destroy event.

Usage

Simple example:

module "beamMP_server" {
  source              = "Harry-Moore-dev/minecraft-server-module/aws"
  version             = "1.0.0"
  s3_save_bucket_name = "some-save-bucket"
}

Detailed example:

module "beamMP_server" {
  source              = "Harry-Moore-dev/minecraft-server-module/aws"
  version             = "1.0.0"
  s3_save_bucket_name = "some-save-bucket"

  region              = "eu-west-1"
  ec2_instance_type   = "t3.large"
  ec2_ebs_volume_size = 8

  ec2_spot_instance_price   = "0.01"
  ec2_spot_instance_enabled = true

  server_port               = 25565
}

Loading save data

This project creates an S3 bucket in your AWS account and load the save data to a path of your choice. All save files in that path will be copied over to the server on creation so sufficient ebs volume size should be specified depending on the size of the saves loaded. On instance termination (if running) the current world will be saved to the s3 bucket for future use.

Pre-commit config

Install dependencies for pre-commit.

brew install pre-commit terraform-docs tflint tfsec

Requirements

Name Version
terraform >= 1.5.7
aws 5.36.0
null >= 3.2.2

Providers

Name Version
aws 5.36.0
null 3.2.2

Modules

Name Source Version
ec2 terraform-aws-modules/ec2-instance/aws 5.6.0
security_group terraform-aws-modules/security-group/aws 5.1.0

Resources

Name Type
aws_default_vpc.default resource
aws_iam_instance_profile.ssm_instance_profile resource
aws_iam_policy.s3_write_policy resource
aws_iam_role.ssm_role resource
aws_iam_role_policy_attachment.s3_write_policy_attachment resource
aws_iam_role_policy_attachment.ssm_policy_attachment resource
aws_subnet.public_subnet resource
null_resource.create_s3_bucket_if_doesnt_exist resource
aws_availability_zones.available data source
aws_ssm_parameter.latest_ami data source

Inputs

Name Description Type Default Required
ec2_architecture ec2 instance architecture string "x86_64" no
ec2_ebs_volume_size ec2 ebs volume size number 15 no
ec2_instance_type ec2 instance type string "t3.large" no
ec2_spot_instance_enabled use ec2 spot instances (cheaper but can be terminated at any time) bool false no
ec2_spot_instance_price ec2 spot instance price (adjust this for the instance type if using spot instances) string "0.01" no
mc_admins A map of admins where the key is the UUID and the value is the username
list(object({
uuid = string
name = string
level = number
bypassesPlayerLimit = bool
}))
[] no
mc_allocated_memory The amount of memory allocated to the Minecraft server java runtime in MB number 1024 no
mc_allow_flight Whether flight is allowed on the Minecraft server bool false no
mc_allow_nether Whether the nether is allowed on the Minecraft server bool true no
mc_custom_seed Specify a custom seed for the Minecraft server (a random seed will be used if not specified) string "" no
mc_difficulty The difficulty for the Minecraft server string "easy" no
mc_enable_command_block Whether command blocks are enabled on the server bool false no
mc_force_gamemode Whether to force the game mode on the Minecraft server bool false no
mc_game_mode The game mode for the Minecraft server string "survival" no
mc_generate_structures Whether structures are generated in the Minecraft server bool true no
mc_hardcore Whether hardcore mode is enabled on the Minecraft server bool false no
mc_level_name The name of the level for the Minecraft server string "world" no
mc_level_type The type of level for the Minecraft server (: character must be double escaped with a backslash) string "minecraft\\:normal" no
mc_max_players The maximum number of players for the Minecraft server number 20 no
mc_max_world_size The maximum world size for the Minecraft server number 29999984 no
mc_name The name of the Minecraft server string "Minecraft Server" no
mc_player_idle_timeout The idle timeout for the Minecraft server (0 to disable) number 0 no
mc_pvp Whether PVP is enabled on the server bool true no
mc_resource_pack The resource pack for the Minecraft server string "" no
mc_simulation_distance The simulation distance for the Minecraft server number 12 no
mc_spawn_animals Whether animals spawn on the Minecraft server bool true no
mc_spawn_monsters Whether monsters spawn on the Minecraft server bool true no
mc_spawn_npcs Whether NPCs spawn on the Minecraft server bool true no
mc_view_distance The view distance for the Minecraft server number 32 no
mc_whitelist_enabled Whether the whitelist is enabled on the Minecraft server bool false no
mc_whitelisted_users A map of whitelisted users where the key is the UUID and the value is the username
list(object({
uuid = string
name = string
}))
[] no
minecraft_version The version of Minecraft Java edition to install, if not specified the latest version will be installed string "" no
notification_webhook_url The URL of the Discord webhook to send notifications to string "https://webhook.site/87aba66d-bdaa-4337-85cf-7ef180f24146" no
region AWS region string "eu-west-2" no
s3_save_bucket_name The S3 bucket name to save the Minecraft server data string n/a yes
s3_save_bucket_versioning Whether to enable versioning on the S3 bucket on first creation string "Enabled" no
server_port The port the server will run on number 25565 no
vpc_subnet_cidr_block value of the vpc cidr block for the public subnet string "172.31.0.0/16" no

Outputs

Name Description
server_ip public IP of the EC2 instance used for direct connect

Packages

 
 
 

Contributors