-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
215 lines (181 loc) · 4.45 KB
/
main.tf
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
data "aws_vpc" "default" {
id = var.vpc_id
}
data "aws_subnet" "default" {
vpc_id = data.aws_vpc.default.id
availability_zone = var.aws_zone
}
data "aws_route53_zone" "selected" {
name = "${var.dns_zone}."
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
data "template_cloudinit_config" "config" {
gzip = true
base64_encode = true
part {
filename = "cloud-init.yml"
content_type = "text/cloud-config"
content = file("cloud-init.yml")
}
part {
content_type = "text/x-shellscript"
content = templatefile("setup.sh", {
tf_version = var.snikket_version
tf_domain = var.domain
tf_admin_email = var.admin_email
tf_import_test_data = var.import_test_data
})
}
}
resource "aws_security_group" "allow_ssh" {
name_prefix = "snikket_allow_ssh_"
description = "Allow SSH access from anywhere"
vpc_id = data.aws_vpc.default.id
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_snikket_all" {
name_prefix = "snikket_allow_ports_"
description = "Allow access to a Snikket server from anywhere"
vpc_id = data.aws_vpc.default.id
ingress {
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "XMPP c2s"
from_port = 5222
to_port = 5223
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "XMPP s2s"
from_port = 5269
to_port = 5269
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "XMPP proxy service"
from_port = 5000
to_port = 5000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_stun_turn_server" {
name_prefix = "snikket_allow_turn_"
description = "Allow access to a STUN/TURN server"
vpc_id = data.aws_vpc.default.id
ingress {
description = "STUN (TCP)"
from_port = 3478
to_port = 3479
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "STUN (UDP)"
from_port = 3478
to_port = 3479
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "TURN (TCP)"
from_port = 5349
to_port = 5350
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "TURN (UDP)"
from_port = 5349
to_port = 5350
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "TURN relay (UDP)"
from_port = 49152
to_port = 65535
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "snikket" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3a.nano"
subnet_id = data.aws_subnet.default.id
associate_public_ip_address = true
vpc_security_group_ids = [
aws_security_group.allow_snikket_all.id,
aws_security_group.allow_stun_turn_server.id,
aws_security_group.allow_ssh.id
]
key_name = var.key_name
user_data_base64 = data.template_cloudinit_config.config.rendered
tags = {
Name = "snikket (${var.domain})"
}
}
resource "aws_route53_record" "primary" {
zone_id = data.aws_route53_zone.selected.zone_id
name = var.domain
type = "A"
ttl = "60"
records = [aws_instance.snikket.public_ip]
}
resource "aws_route53_record" "groups" {
zone_id = data.aws_route53_zone.selected.zone_id
name = "groups.${var.domain}"
type = "CNAME"
ttl = "60"
records = [aws_route53_record.primary.name]
}
resource "aws_route53_record" "share" {
zone_id = data.aws_route53_zone.selected.zone_id
name = "share.${var.domain}"
type = "CNAME"
ttl = "60"
records = [aws_route53_record.primary.name]
}