Skip to content

Terraform Module to deploy a simple Minecraft Server using Oracle Cloud's Always Free Tier

Notifications You must be signed in to change notification settings

maishiroma/OracleMCServer

Repository files navigation

Oracle Cloud Minecraft Server Automation

This repository contains a barebone, deployment of a Minecraft Server using Oracle Cloud.

The configuration in here, by default, creates an instance that abides by the Always Free Tier that Oracle Cloud provides for all customers. Setting different configurations to go past the Always Free Tier is allowed, but the price of said deployment will vary.

Goal of Deployment

Since I created a more complex deployment over here, I wanted to see if I can just create a simpler deployment that can manage a Minecraft server using systemd. This will greatly simplify managing the instance since you would only need to know how to use systemd services to manage the server lifecycle.

Features

  • Managing minecraft service on instance via systemd
  • Backup and Restore from Backups done via Scripts (currently need to call manually on instance)
  • Can auto setup either vanilla or a Forge server
  • Automatic bootstrap and startup of Minecraft Server
  • Cost Saving Module; Bare Minimum Setup to get going
  • Ability to sync mods from Object Storage
  • Ability to initially pass a custom server.properties and an ops.json to the instance
  • Auto Backup via CronJob (Defaults to once a week on Friday at 3PM)
  • Ability to easily add more TCP/UDP ports if needed
    • These TCP/UDP ports are only accessible by IPS that have access to the game

Architecture Diagram

This deployment creates the following items:

  • One Identity Compartment to group all of these deployments into for easier management
    • One Dynamic Group with a Dynamic Policy to access Object Storage Buckets
  • An Object Storage Bucket
  • An instance configuration
  • An instance pool
  • A VPC with
    • One public subnet
    • One Internet Gateway
    • One Route Table
    • One Security List that allows for:
      • Port 22 Traffic
      • Port 25565 Traffic

Requirements

Name Version
terraform > 0.12
oci = 4.121.0
random = 3.5.1
template = 2.2.0

Providers

Name Version
oci = 4.121.0
random = 3.5.1
template = 2.2.0

Modules

No modules.

Resources

Name Type
oci_core_default_route_table.self resource
oci_core_instance_configuration.self resource
oci_core_instance_pool.self resource
oci_core_internet_gateway.self resource
oci_core_security_list.self resource
oci_core_subnet.public resource
oci_core_vcn.self resource
oci_identity_compartment.self resource
oci_identity_dynamic_group.self resource
oci_identity_policy.bucket_service resource
oci_identity_policy.self resource
oci_objectstorage_bucket.self resource
oci_objectstorage_object_lifecycle_policy.self resource
random_string.unique resource
oci_core_instance.self data source
oci_core_instance_pool_instances.self data source
oci_objectstorage_namespace.self data source
template_cloudinit_config.self data source
template_file.fact_file data source
template_file.minecraft_service data source
template_file.modded_user_jvm_args data source
template_file.rclone_conf data source

Inputs

Name Description Type Default Required
additional_tcp_ports A list of additional TCP ports to open up on the instance for access via the game_ip_addresses list(number) [] no
additonal_udp_ports A list of additional UCP ports to open up on the instance for access via the game_ip_addresses list(number) [] no
admin_ip_addresses List of IPs to allow SSH access list(string) [] no
availability_domain The az to put the instance in. Note that this default is for us-sanjose-1 string "gEpX:US-SANJOSE-1-AD-1" no
backup_crontime The time in crontime for auto backups to run via a cronjob. Defaults to once a week on Friday at 3PM string "0 15 * * 5" no
custom_ops_json_path The path to a custom ops.json that is used for the server. Leave blank to not use assign anyone ops string "" no
custom_server_properties_path The path to a custom server.properites that is used for this server. Leave blank to use the default string "" no
existing_pub_subnet The ID of an existing public subnet. If left at "", will create a new VPN and associate this instance to it string "" no
game_ip_addresses List of IPs to allow minecraft access list(string) [] no
is_modded Is this server a modded one? Defaults to False. bool false no
max_memory The max amount of RAM allocate to the server string "5G" no
min_memory The min amount of RAM allocate to the server string "1G" no
minecraft_server_jar_download_url The URL that allows one to download the server JAR of their choice. Defaults to a vanilla MC server. string "https://piston-data.mojang.com/v1/objects/8f3112a1049751cc472ec13e397eade5336ca7ae/server.jar" no
parent_compartment_id The parent compartment to associate the deployment's compartment. string n/a yes
project_name The name of this project string "mc-server" no
pub_key The public key to associate on the instance in order to provide SSH access string n/a yes
pub_subnet_block The CIDR block to use for the subnet string "10.0.0.0/24" no
region_name The name of the region string "us-sanjose-1" no
vm_image The image ID that is used for the VM. Note that this default is for us-sanjose-1. string "ocid1.image.oc1.us-sanjose-1.aaaaaaaaxnfbpr6wcawvbgx56ls5v2lndcmp7q3e7guu3rkrwcfhecouxslq" no
vm_shape The shape of the VM. The default is part of the Always Free Tier string "VM.Standard.A1.Flex" no
vm_specs The specs of the VM. Note that the default is part of the Always Free Tier map(string)
{
"cpus": "2",
"memory": "6"
}
no
vpc_cidr_block The CIDR block to use for the VPC string "10.0.0.0/16" no

Outputs

Name Description
backup_bucket_name The name of the bucket that holds world backups and mods for the server
pub_subnet_id The OICD of the created public subnet, if it exists.
server_public_ip The public IP of the created server in the instance pool.

Steps to Deploy

  1. Make sure you have the following already configured on your computer:
  • terraform >= 0.12
  • Oracle Cloud Credentials
    • To authenticate terraform with your OCI account, see this
  1. Create a new terraform root with the following configuration, making sure to fill in the values for "...":
provider "oci" {
  region           = "..."
  # There are a multitude of ways to authenticate to OCI;
  # please see the docs for your preferred method.
}

terraform {
  # The state is stored locally
  backend "local" {
    path = "./terraform.tfstate"
  }
}


module "mc_server" {
  # This sources the module to whatever is on latest
  # You can either use a tag or alternatively clone this repo and source
  # this module as a local module for more stability
  source = "git@github.com:maishiroma/OracleMCServer.git?ref=main"

  parent_compartment_id = "..."
  region_name           = "..."

  pub_key = ""

  admin_ip_addresses = ["..."]
  game_ip_addresses  = ["..."]
}
  1. Run terraform init and terraform plan to confirm the deployment
  2. If everything looks good, terraform apply

Managing

All of these need to be done via ssh into the instance

  • Restarting Server: sudo systemctl restart minecraft
  • Stopping Server: sudo systemctl stop minecraft
  • Status of Server: sudo systemctl status minecraft
  • Creating a world backup: cd /etc && sudo ./backup.sh
    • World Backups are saved in the created Object Bucket that is made
  • Restoring from a named backup: cd /etc && sudo ./restore_backup.sh <name_of_backup>
  • Syncing Mods from bucket: cd /etc && sudo ./mod_refresh.sh
    • This is available if server_type is set to something besides vanilla
  • Adjusting the server.properites and/or ops.json
    • Make changes in TF and apply them to the instance
    • Reboot instance

All of the following are services that are done via the OCI Console:

  • Shutting Down Instance: OCI Console -> Instances -> Instance Pools -> Select Instance Pool, mc-server-XXXX -> Stop
    • This is optimal when you want to save funds on the instance if no one is using it at the current moment

Cleaning Up

In the case that the server is no longer needed, the following should be done:

  1. MAKE A BACKUP OF THE WORLD on the instance using the backup script.
  2. Download said backup from the object storage to your local computer.
  3. Run terraform destroy on your existing TF code that you used earlier
  4. Confirm and all resources for the server are now removed

About

Terraform Module to deploy a simple Minecraft Server using Oracle Cloud's Always Free Tier

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published