Skip to content

Instantly share code, notes, and snippets.

@jtopjian
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtopjian/504a6bed834a7ba2bc13 to your computer and use it in GitHub Desktop.
Save jtopjian/504a6bed834a7ba2bc13 to your computer and use it in GitHub Desktop.
Deploy Minecraft with Terraform
#!/bin/bash
useradd -m minecraft
apt-get update
apt-get install -y openjdk-7-jre-headless wget
cd /home/minecraft
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.8.3/minecraft_server.1.8.3.jar
cat >/home/minecraft/eula.txt<<EOF
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Tue Jan 27 21:40:00 UTC 2015
eula=true
EOF
chown -R minecraft: /home/minecraft
cat >/etc/init/minecraft.conf<<EOF
start on runlevel [2345]
stop on runlevel [^2345]
console log
chdir /home/minecraft
setuid minecraft
setgid minecraft
respawn
respawn limit 20 5
exec /usr/bin/java -Xms1536M -Xmx2048M -jar minecraft_server.1.8.3.jar nogui
EOF
start minecraft
# Please be aware that you will only be able to access the Minecraft server using a Minecraft client.
# No other access is possible.
# This is truly an emphemeral, disposable Minecraft service.
resource "openstack_compute_secgroup_v2" "minecraft" {
name = "minecraft"
description = "security rules for minecraft"
rule {
from_port = 25565
to_port = 25565
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_floatingip_v2" "minecraft" {
pool = "nova"
}
resource "openstack_compute_instance_v2" "minecraft" {
name = "minecraft"
image_name = "Ubuntu 14.04"
flavor_name = "m1.medium"
security_groups = ["${openstack_compute_secgroup_v2.minecraft.name}"]
floating_ip = "${openstack_compute_floatingip_v2.minecraft.address}"
user_data = "${file("minecraft.sh")}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment