Skip to content

Commit 1d65ac4

Browse files
author
Chris Herrmann
committed
Initial commit
0 parents  commit 1d65ac4

File tree

16 files changed

+1146
-0
lines changed

16 files changed

+1146
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.terraform
2+
*.retry

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Chat
2+
3+
Synapse server for https://chat.python.nz.

infrastructure/main.tf

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
terraform {
2+
backend "swift" {
3+
region_name = "nz-hlz-1"
4+
5+
container = "terraform-state/chat/"
6+
}
7+
}
8+
9+
provider "openstack" {
10+
region = "nz-hlz-1"
11+
}
12+
13+
#--------------------------------------------------------------
14+
# Networking
15+
#--------------------------------------------------------------
16+
resource "openstack_networking_router_v2" "router" {
17+
name = "${var.router_name}"
18+
external_network_id = "${var.external_network_id}"
19+
}
20+
21+
resource "openstack_networking_network_v2" "private_net" {
22+
name = "${var.network_name}"
23+
admin_state_up = "${var.admin_state_up}"
24+
}
25+
26+
resource "openstack_networking_subnet_v2" "subnet" {
27+
name = "${var.subnet_name}"
28+
network_id = "${openstack_networking_network_v2.private_net.id}"
29+
30+
allocation_pools {
31+
start = "${var.pool_start}"
32+
end = "${var.pool_end}"
33+
}
34+
35+
enable_dhcp = "${var.enable_dchp}"
36+
cidr = "${var.cidr}"
37+
ip_version = "${var.ip_version}"
38+
}
39+
40+
resource "openstack_networking_router_interface_v2" "router_interface" {
41+
router_id = "${openstack_networking_router_v2.router.id}"
42+
subnet_id = "${openstack_networking_subnet_v2.subnet.id}"
43+
}
44+
45+
#--------------------------------------------------------------
46+
# Security Groups
47+
#--------------------------------------------------------------
48+
resource "openstack_networking_secgroup_v2" "base" {
49+
name = "base"
50+
description = "Allow port 22 ingress and egress to internet"
51+
}
52+
53+
resource "openstack_networking_secgroup_rule_v2" "ssh" {
54+
direction = "ingress"
55+
ethertype = "IPv4"
56+
protocol = "tcp"
57+
port_range_min = 22
58+
port_range_max = 22
59+
remote_ip_prefix = "0.0.0.0/0"
60+
security_group_id = "${openstack_networking_secgroup_v2.base.id}"
61+
}
62+
63+
resource "openstack_networking_secgroup_rule_v2" "egress" {
64+
direction = "egress"
65+
ethertype = "IPv4"
66+
remote_ip_prefix = "0.0.0.0/0"
67+
security_group_id = "${openstack_networking_secgroup_v2.base.id}"
68+
}
69+
70+
# Synapes Homeserver Security Group
71+
resource "openstack_networking_secgroup_v2" "synapse_homeserver" {
72+
name = "synapse-homeserver"
73+
description = "Allow ports for synapse homeserver"
74+
}
75+
76+
resource "openstack_networking_secgroup_rule_v2" "http" {
77+
direction = "ingress"
78+
ethertype = "IPv4"
79+
protocol = "tcp"
80+
port_range_min = 80
81+
port_range_max = 80
82+
remote_ip_prefix = "0.0.0.0/0"
83+
security_group_id = "${openstack_networking_secgroup_v2.synapse_homeserver.id}"
84+
}
85+
86+
resource "openstack_networking_secgroup_rule_v2" "https" {
87+
direction = "ingress"
88+
ethertype = "IPv4"
89+
protocol = "tcp"
90+
port_range_min = 443
91+
port_range_max = 443
92+
remote_ip_prefix = "0.0.0.0/0"
93+
security_group_id = "${openstack_networking_secgroup_v2.synapse_homeserver.id}"
94+
}
95+
96+
resource "openstack_networking_secgroup_rule_v2" "synapse_federation" {
97+
direction = "ingress"
98+
ethertype = "IPv4"
99+
protocol = "tcp"
100+
port_range_min = 8448
101+
port_range_max = 8448
102+
remote_ip_prefix = "0.0.0.0/0"
103+
security_group_id = "${openstack_networking_secgroup_v2.synapse_homeserver.id}"
104+
}
105+
106+
resource "openstack_compute_keypair_v2" "erp_deploy" {
107+
name = "${var.public_key_name}"
108+
public_key = "${var.public_key_value}"
109+
}
110+
111+
#--------------------------------------------------------------
112+
# Instances
113+
#--------------------------------------------------------------
114+
resource "openstack_compute_instance_v2" "synapse_homeserver" {
115+
name = "${var.name}"
116+
image_name = "${var.image}"
117+
flavor_name = "${var.flavor}"
118+
key_pair = "${openstack_compute_keypair_v2.erp_deploy.name}"
119+
security_groups = [
120+
"${openstack_networking_secgroup_v2.base.name}",
121+
"${openstack_networking_secgroup_v2.synapse_homeserver.name}"
122+
]
123+
}
124+
125+
resource "openstack_networking_floatingip_v2" "floating_ip" {
126+
pool = "public-net"
127+
}
128+
129+
resource "openstack_compute_floatingip_associate_v2" "floating_ip" {
130+
floating_ip = "${openstack_networking_floatingip_v2.floating_ip.address}"
131+
instance_id = "${openstack_compute_instance_v2.synapse_homeserver.id}"
132+
}
133+
134+
resource "openstack_blockstorage_volume_v2" "synapse_homeserver" {
135+
name = "synapse-homeserver-volume"
136+
size = "${var.volume_size}"
137+
}
138+
139+
resource "openstack_compute_volume_attach_v2" "synapse_homeserver" {
140+
instance_id = "${openstack_compute_instance_v2.synapse_homeserver.id}"
141+
volume_id = "${openstack_blockstorage_volume_v2.synapse_homeserver.id}"
142+
device = "${var.volume_device}"
143+
}

infrastructure/terraform.tfvars

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#--------------------------------------------------------------
2+
# Network
3+
#--------------------------------------------------------------
4+
external_network_id = "f10ad6de-a26d-4c29-8c64-2a7418d47f8f"
5+
6+
#--------------------------------------------------------------
7+
# Instances
8+
#--------------------------------------------------------------
9+
name = "synapse-homeserver"
10+
image = "ubuntu-18.04-x86_64"
11+
flavor = "c1.c1r4"
12+
public_key_name = "chris"
13+
public_key_value = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCwcdE5l07+no9EccvG4ZDoi9EM3+3DY0QQgGsETMamogHsthiQOJBsDPHrWR57KI8QJxn4d+kaBRpFqexn4XziFUGrJEVgRyAXY3Qt7fwSHFDdU6o+aoRTZfH8eiPpBe4UYF6JE9KXsMOQHuIza4HLHJ/agxuB17Kteq6BBCT08yzgYYkJvjJQ72TbR+i5HyB72OMctAQeolLcIA2AW4iTYfmcHLopT4mrtzyFKD99zsjPFZP1UPfYrJzIivu8F7i5JjApO6hy11KbdKJeb3jYLWjCSp6/+OLo75nwcwe6f4R2pk1L7QT/z5ZvidzEBfljKoU7ouBbwTs2jnGlafB7BdZBkVHzBkInfHN6paWZRhzEL5txEllAd2uZqzQ/3zlsfMQLfKfKP5ODK7JPBHRxaIW41gNuR/BYHDbWuutSLae9niM8cVB/JwfMyqZjzXrvcBBoDqUanJ2TsPo6l3DQwvKcXQ9n48WGMnEA2mLfc0e29PPJZkXh0bZmJVeA+40aVXzLEIMkW7dHQuCNEV49qntGfFz6gazQyfzxOpV1nx5cfzZ9r5lku09R7QIQDJ1MhVUym6tOkYW1QveoIlZBQccEnh6gyo7rF4qgOLQXhoAp889CR55Nudvd/TpaGwiQ2N8Cng85fJCVenPH6t0tRt3uYq0JPzUf8bLmZPcBKQ== chrisherrmann@chrisherrmann-pc"
14+
15+
#--------------------------------------------------------------
16+
# Volume
17+
#--------------------------------------------------------------
18+
volume_size = 100
19+
volume_device = "/dev/vdb"

infrastructure/variables.tf

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#--------------------------------------------------------------
2+
# Network
3+
#--------------------------------------------------------------
4+
variable "external_network_id" {}
5+
6+
variable "router_name" {
7+
default = "border-router"
8+
}
9+
10+
variable "network_name" {
11+
default = "private-net"
12+
}
13+
14+
variable "admin_state_up" {
15+
default = "true"
16+
}
17+
18+
variable "subnet_name" {
19+
default = "private-subnet"
20+
}
21+
22+
variable "pool_start" {
23+
default = "10.0.0.10"
24+
}
25+
26+
variable "pool_end" {
27+
default = "10.0.0.200"
28+
}
29+
30+
variable "enable_dchp" {
31+
default = "true"
32+
}
33+
34+
variable "cidr" {
35+
default = "10.0.0.0/24"
36+
}
37+
38+
variable "ip_version" {
39+
default = "4"
40+
}
41+
42+
variable "public_key_name" {}
43+
variable "public_key_value" {}
44+
45+
#--------------------------------------------------------------
46+
# Instances
47+
#--------------------------------------------------------------
48+
variable "name" {}
49+
variable "image" {}
50+
variable "flavor" {}
51+
52+
#--------------------------------------------------------------
53+
# Volume
54+
#--------------------------------------------------------------
55+
variable "volume_size" {}
56+
variable "volume_device" {}

openrc.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
export OS_AUTH_URL=https://api.cloud.catalyst.net.nz:5000/v2.0
4+
export OS_TENANT_ID=b25589432c544c0e8ae266b9871532e8
5+
export OS_TENANT_NAME="new-zealand-python-user-group-incorporated"
6+
7+
echo "Please enter your OpenStack Username for project $OS_TENANT_NAME: "
8+
read -r OS_USERNAME_INPUT
9+
export OS_USERNAME=${OS_USERNAME_INPUT}
10+
11+
echo "Please enter your OpenStack Password for project $OS_TENANT_NAME: "
12+
read -sr OS_PASSWORD_INPUT
13+
export OS_PASSWORD=${OS_PASSWORD_INPUT}
14+
15+
export OS_REGION_NAME="nz-hlz-1"
16+
17+
if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi
18+
19+
export OS_ENDPOINT_TYPE=publicURL
20+
export OS_IDENTITY_API_VERSION=2

provisioning/ansible.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[defaults]
2+
inventory = hosts
3+
host_key_checking = False

provisioning/files/favicon.ico

1.12 KB
Binary file not shown.

provisioning/files/img/logo-small.png

8.11 KB
Loading

provisioning/files/img/logo.png

8.11 KB
Loading

provisioning/host_vars/chat.python.nz

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
remote_user: ubuntu
2+
home: /home/ubuntu
3+
4+
synapse_path: "{{ home }}/synapse"
5+
synapse_config_path: "{{ synapse_path }}/homeserver.yaml"
6+
logo_path: /data/_matrix/client/img
7+
8+
images:
9+
- favicon.ico
10+
- img/logo.png
11+
- img/logo-small.png
12+
13+
volume_device: /dev/vdb # As per the value in Terraform

provisioning/hosts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chat.python.nz

0 commit comments

Comments
 (0)