This repository contains infrastructure as code (IaC) and configuration management scripts to automatically deploy and configure a Minecraft server on AWS. The deployment is fully automated using Terraform for infrastructure provisioning and Ansible for server configuration.
This project demonstrates modern DevOps practices by automating the deployment of a Minecraft server using:
- Infrastructure as Code (Terraform)
- Configuration Management (Ansible)
- AWS CLI v2.x
- Terraform v1.x
- Ansible v2.x
- Git
- Install AWS CLI and configure credentials:
aws configureYou'll be prompted to enter:
- AWS Access Key ID
- AWS Secret Access Key
- Default region name (e.g., us-west-2)
- Default output format (press Enter for default)
-
For AWS Academy credentials, you may need to manually add the session token:
- Open
~/.aws/credentials - Add
aws_session_token = your_session_tokenunder the [default] section - The file should look like:
[default] aws_access_key_id = your_access_key aws_secret_access_key = your_secret_key aws_session_token = your_session_token
- Open
-
Required AWS permissions:
- EC2 full access
- VPC full access
- IAM role creation
- Security group management
The deployment automatically:
- Generates a new RSA key pair
- Creates the key pair in AWS
- Saves the private key as
terraform/minecraft-server-ssh.pem - Uses the key pair for the EC2 instance
The private key file will be created in the terraform directory after running terraform apply. Keep this file secure as it's needed to SSH into your Minecraft server.
-
Infrastructure Provisioning
cd terraform terraform init terraform plan terraform apply -
Get Server IP and Set Environment Variable
# Get the server IP from Terraform output export MINECRAFT_SERVER_IP=$(terraform output -raw minecraft_server_ip)
-
Server Configuration
cd ../ansible ansible-playbook -i inventory.yml minecraft.yml
- Navigate to the terraform directory:
cd terraform - Destroy the infrastructure:
This will:
terraform destroy
- Stop and terminate the EC2 instance
- Remove the security group
- Clean up any other AWS resources created by Terraform
- Log into AWS Console
- Navigate to EC2 Dashboard
- Find your running instance
- Select the instance and click "Instance state" → "Stop instance"
- Note: This only stops the instance but keeps all resources intact
- To completely remove resources, use Option 1 (terraform destroy)
graph TD
A[Local Deployment] --> B[Terraform]
B --> C[AWS Infrastructure]
C --> D[EC2 Instance]
D --> E[Minecraft Server]
F[Ansible] --> D
After deployment:
nmap -sV -Pn -p T:25565 <instance_public_ip>- The server's public IP will be output after Terraform completes
- Connect using Minecraft client with the server address:
minecraft://<instance_public_ip>:25565
.
├── README.md
├── terraform/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf
└── ansible/
├── inventory.yml
└── minecraft.yml