forked from dirien/pulumi-python-minecraft
-
Notifications
You must be signed in to change notification settings - Fork 1
/
minecraft_component.py
109 lines (98 loc) · 6.13 KB
/
minecraft_component.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pulumi
from pulumi_aws import s3
from pulumi_aws import ec2, get_ami, GetAmiFilterArgs
class MyMinecraftServer(pulumi.ComponentResource):
def __init__(self, name, opts=None):
super().__init__('minecraft:index:MyMinecraftServer', name, None, opts)
minecraft_vpc = ec2.Vpc("minecraft-vpc",
cidr_block="10.0.0.0/16",
enable_dns_hostnames=True,
enable_dns_support=True,
opts=pulumi.ResourceOptions(parent=self))
minecraft_subnet = ec2.Subnet("minecraft-subnet",
vpc_id=minecraft_vpc.id,
cidr_block="10.0.48.0/20",
map_public_ip_on_launch=True,
availability_zone="eu-central-1a",
opts=pulumi.ResourceOptions(parent=self))
minecraft_internet_gateway = ec2.InternetGateway("minecraft-internet-gateway",
vpc_id=minecraft_vpc.id,
opts=pulumi.ResourceOptions(parent=self))
minecraft_route_table = ec2.RouteTable("minecraft-route-table",
vpc_id=minecraft_vpc.id,
routes=[{
"cidr_block": "0.0.0.0/0",
"gateway_id": minecraft_internet_gateway.id,
}],
opts=pulumi.ResourceOptions(parent=self))
minecraft_route_table_association = ec2.RouteTableAssociation("minecraft-route-table-association",
subnet_id=minecraft_subnet.id,
route_table_id=minecraft_route_table.id,
opts=pulumi.ResourceOptions(parent=self))
minecraft_security_group = ec2.SecurityGroup("minecraft-security-group",
description="Allow Minecraft traffic",
vpc_id=minecraft_vpc.id,
ingress=[
ec2.SecurityGroupIngressArgs(
description="Minecraft",
protocol="tcp",
from_port=25565,
to_port=25565,
cidr_blocks=[
"0.0.0.0/0"
]
),
ec2.SecurityGroupIngressArgs(
description="SSH",
protocol="tcp",
from_port=22,
to_port=22,
cidr_blocks=[
"0.0.0.0/0"
]
)
],
egress=[
ec2.SecurityGroupEgressArgs(
description="All",
protocol="-1",
from_port=0,
to_port=0,
cidr_blocks=[
"0.0.0.0/0"
]
)
],
opts=pulumi.ResourceOptions(parent=self))
minecraft_ami = ec2.get_ami(filters=[
GetAmiFilterArgs(
name="name",
values=[
"ubuntu-minimal/images/hvm-ssd/ubuntu-jammy-22.04*"
],
),
GetAmiFilterArgs(
name="architecture",
values=[
"x86_64"
],
)
], most_recent=True, owners=["099720109477"])
minecraft_keypair = ec2.KeyPair("minecraft-keypair",
public_key=open(
"minecraft.pub").read(),
opts=pulumi.ResourceOptions(parent=self))
minecraft_vm = ec2.Instance("minecraft-vm",
instance_type="t3.xlarge",
ami=minecraft_ami.id,
subnet_id=minecraft_subnet.id,
vpc_security_group_ids=[
minecraft_security_group.id
],
key_name=minecraft_keypair.key_name,
user_data=open("cloud-init.yaml").read(),
opts=pulumi.ResourceOptions(parent=self))
self.public_ip = minecraft_vm.public_ip
self.register_outputs({
"minecraft_vm_ip": minecraft_vm.public_ip
})