This project automates the setup of a Minecraft Server on AWS EC2 instances using Terraform and a bash script, you can run a Minecraft server with just a terraform apply.
The server is configured to run on ARM-based instances, so, if you want to run this on x86 arch, you need to do some customizations to the Shell Script.
- AWS Account: You need an active AWS account.
- Terraform: Terraform must be installed on your local machine. Download it from Terraform's official website.
- EC2 Key Pair: An EC2 key pair should be available for SSH access to the instance.
- Create a
terraform.tfvarsfile in the same directory as your other Terraform files. This file will be used to set input variables that should be customized based on your environment. - Edit the
terraform.tfvarsfile to include necessary details such as your EC2 instance type, key pair name, and other configurations. Here’s an example of what this file might look like:minecraft_version_url = "<URL>" # Check the URL's at the end of the docs aws_region = "us-east-1" aws_access_key = "<ACCESS_KEY>" aws_secret_key = "<SECRET_KEY>" aws_host_ami_id = "ami-0eb01a520e67f7f20" aws_host_type = "t4g.small" pem_file = "minecraft"
- Save the changes to your
terraform.tfvarsfile.
- Navigate to the project directory where the Terraform files are located.
- Initialize Terraform:
This will download the necessary plugins and prepare your directory for Terraform deployment.
terraform init
-
Plan the Terraform deployment to see the resources that will be created:
terraform plan -var-file=terraform.tfvars
-
Apply the Terraform configuration to start the deployment:
terraform apply -var-file=terraform.tfvars
-
Confirm the action by typing
yeswhen prompted. -
After that let EC2 run the Shell script to start the Minecraft Server and you are good to go.
Once the Minecraft server is set up, it will start automatically. You can manage the server using the following systemd commands:
- Start the server:
sudo systemctl start minecraft.service
- Stop the server:
sudo systemctl stop minecraft.service
- Enable server to start on boot:
sudo systemctl enable minecraft.service
Modify the variables.tf and minecraft-setup.sh to adjust configurations such as the Minecraft version and server settings.
Credits to @cliffano URLs are taken from his contribution here
Feel free to fork this project and submit pull requests or create issues if you find bugs or have features you’d like to suggest.
This project is released under the MIT License. See the LICENSE file for details.
