Breaking blocks with Terraform | S01 E02 | Build On Weekly
Do you need a Minecraft Server? Today, we deploy one with Terraform
- You can now view the costs of your Terraform templates, straight from Visual Studio code with this Infracost plugin: https://github.com/infracost/vscode-infracost
- Looking to build Web applications with some dotnet? Well Blazor WebAssembly is maybe for you. Our colleague Francois, wrote a blog post on some first steps when it comes to using the ASP.NET Core Blazor WebAssembly framework: Medium Blog post
- If you are looking to build products with the same Design System we use here at AWS, check out CloudScape - an open source solution to building user experiences: https://cloudscape.design/
- Carbon Language - An experimental successor to C++: GitHub repo
- Are you having fun with Machine Learning? Go and teach yourself beginner GPU programming with this wonderful notebook: GitHub repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Setting up the AWS Terraform provider
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.22"
}
}
}
provider "aws" {
profile = "default"
region = "us-west-2"
}
# Just a variable with the URL to the Minecraft server JAR (this changes over time)
variable "mojang_server_url" {
type = string
default = "https://launcher.mojang.com/v1/objects/e00c4052dac1d59a1188b2aa9d5a87113aaf1122/server.jar"
}
# Security - we need to allow a specific port to our EC2 instance
resource "aws_security_group" "minecraft" {
ingress {
description = "Minecraft port"
from_port = 25565
to_port = 25565
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
description = "Send Anywhere"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "Minecraft Security Group"
}
}
# EC2 Instance - THIS is where our Minecraft server runs
resource "aws_instance" "minecraft" {
ami = "ami-098e42ae54c764c35"
instance_type = "t2.xlarge"
vpc_security_group_ids = [aws_security_group.minecraft.id]
associate_public_ip_address = true
## This role is specific to my account, so make sure to attach an IAM role relevant to your setup.
iam_instance_profile = "SSMEC2Role"
root_block_device {
volume_size = 30
}
## This is a bash script that will be executed during the first launch of the Virtual Machine, and it sets up all we need to run Minecraft
user_data = <<-EOF
#!/bin/bash
sudo yum -y update
sudo rpm --import https://yum.corretto.aws/corretto.key
sudo curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo
sudo yum install -y java-17-amazon-corretto-devel.x86_64
wget -O server.jar ${var.mojang_server_url}
java -Xmx1024M -Xms1024M -jar server.jar nogui
sed -i 's/eula=false/eula=true/' eula.txt
screen -d -m java -Xmx1024M -Xms1024M -jar server.jar nogui
EOF
tags = {
Name = "Minecraft Server"
}
}
output "instance_ip_addr" {
value = aws_instance.minecraft.public_ip
}
- Infrastructure as Code: Wiki page
- Terraform: Terraform documentation
- Github repo we based our build on: GitHub repo
- Minecraft server download URL: Where you can find the server URL
- AWS SSM - Session manager: Docs page
- GNU Screen: Website
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.